tag:blogger.com,1999:blog-4144304653010663466.post8634529368115493106..comments2012-02-19T10:09:40.197-08:00Comments on David's Software Blog: C is not a subset of C++David Colesnoreply@blogger.comBlogger8125tag:blogger.com,1999:blog-4144304653010663466.post-11826564401627092942012-02-19T10:09:40.197-08:002012-02-19T10:09:40.197-08:00Whoops! C++10++ perhaps? :pWhoops! C++10++ perhaps? :pDavidhttps://www.blogger.com/profile/00838522254587609230noreply@blogger.comtag:blogger.com,1999:blog-4144304653010663466.post-41105871079528809022012-02-19T09:15:15.182-08:002012-02-19T09:15:15.182-08:00I think you mean C++11 :)I think you mean C++11 :)Brucehttps://www.blogger.com/profile/09719457172432224436noreply@blogger.comtag:blogger.com,1999:blog-4144304653010663466.post-69297727315242479762012-02-10T22:09:16.997-08:002012-02-10T22:09:16.997-08:00@Bruce Well that&#39;s not too surprising given th...@Bruce Well that&#39;s not too surprising given that C++98 standard came out almost a decade after the C89 ANSI standard, thus most of C++ is directly compatible.<br /><br />C++10 also brings C++ more inline with C99 - which is likely the reason for Visual C++ adding than deciding to support the current C standard (http://connect.microsoft.com/VisualStudio/feedback/details/531634/support-iso-c99-standard). Especially with things like WinRT on the horizon, it&#39;s pretty clear that C++ is the lingua franca for Microsoft platforms .Davidhttps://www.blogger.com/profile/00838522254587609230noreply@blogger.comtag:blogger.com,1999:blog-4144304653010663466.post-68295884117026467372012-02-10T03:20:39.882-08:002012-02-10T03:20:39.882-08:00@David That&#39;s not quite true: Visual C++ does ...@David That&#39;s not quite true: Visual C++ does have a proper C89 compiler - it&#39;s just that IntellSense in the IDE sometimes doesn&#39;t understand C features (like not having to cast from void*). Visual C++ 2010 even introduced a stdint.h header.Brucehttps://www.blogger.com/profile/09719457172432224436noreply@blogger.comtag:blogger.com,1999:blog-4144304653010663466.post-24859934760662467612011-11-15T23:19:36.148-08:002011-11-15T23:19:36.148-08:00@torg: That&#39;s a very valid point. Certainly C ...@torg: That&#39;s a very valid point. Certainly C support in Visual Studio is largely limited to features that are part of C++. And since the vast majority of Windows developers use Visual Studio as their compiler, any C feature not in C++ in your code (not just headers) will cause you grief.<br /><br />And while it&#39;s true that in most cases you can avoid initializers, I can think of three sensible use-cases for them:<br />1. Constant Arrays and Structs (since you can&#39;t initialize them later)<br />2. For Static and Global variables (otherwise you need to explicitly initialize them in the main function. You also lose the nice &quot;set once&quot; feature of static variables)<br />3. Designated initializers zero out unspecified values (Particularly handy for semi-opaque structures).Davidhttps://www.blogger.com/profile/00838522254587609230noreply@blogger.comtag:blogger.com,1999:blog-4144304653010663466.post-37321399863063338982011-11-15T09:03:27.370-08:002011-11-15T09:03:27.370-08:00if you use designated initializers, you can kiss a...if you use designated initializers, you can kiss any portability to c++ goodbye.<br /><br />Did you know that a function called Init() { abc[42]=1; abc[43]=2; } compiles on everything?torghttps://www.blogger.com/profile/06931551689961561992noreply@blogger.comtag:blogger.com,1999:blog-4144304653010663466.post-17633272124212778272011-11-14T23:11:54.502-08:002011-11-14T23:11:54.502-08:00I believe that initializer lists are implemented v...I believe that initializer lists are implemented via a method that takes a std::initializer_list. Trying to automatically map them to C++ classes would be a bad idea, thus having an explicit overload seems sensible.<br /><br />Interesting point about the C++ vs. C specs. I guess it&#39;s really just clearing up undefined behavior which is always a good thing. Now if C and C++ came up with opposing definitions in the standards...Davidhttps://www.blogger.com/profile/00838522254587609230noreply@blogger.comtag:blogger.com,1999:blog-4144304653010663466.post-28371658394166596882011-11-14T21:59:38.084-08:002011-11-14T21:59:38.084-08:00Didn&#39;t know about designated initialisers. I c...Didn&#39;t know about designated initialisers. I can see why they&#39;re good for structs; not so sure about arrays. In C++, DIs on structs would be hard to slot into the language because of private variables and constructors -- how does C++ handle initialiser lists at all? I assume they don&#39;t work if you have any private variables or no default constructor? In any case, it would be good to support them on POD types for compatibility with C.<br /><br />Here is a subtle one, relevant to our recent discussion on division. Classic C does not define which way it rounds if you divide by a negative number. C++ similarly does not define it. C99, however, defines that it rounds up (which is shit, but efficient). Thus if you take C99 code and move it to C++, you may find your division rounding the wrong way! (But it is likely that most C++ implementations do round up as well.)Anonymousnoreply@blogger.com