|
-
July 26th, 2009, 10:31 PM
#7
Re: Can any C program be compiled with the C++ compiler and obtain a useful executabl
Actually, none of us are guessing, though I qualified my own response. I wrote in C for years before C++ was made available, though I've not studied the C99 standard; never had a reason.
Speedo's point is rather pertinent. My point is we're left to guess exactly what they mean without performing an experiment. They're correct that Objective-C is tacked onto C, and if the compiler is otherwise C99 compliant, Speedo's and Lindley's examples would compile.
However, it gets complicated because the same compilers have an "Objective-C++" mode, where Speedo's example would also give rise to a complaint. Further, there are several versions of GCC supporting Objective-C and Objective-C++, each with their own quirks and levels of compliance for all of the supported language standards.
This gives support to their claim in the article, but as we're observing, they're minor issues (red herrings, in my view).
Modern C++ compilers will operate in a C mode, much like GCC does. That is, if you used a typical modern compiler to compile C99 code, it would produce an executable and pass C99 constructs without complaint, subject to it's own quirks, because it was NOT compiling in a C++ mode. This means the article may be technically correct, but not meaningfully honest and accurate. In other words, we can freely mix C and C++ code in a project, and compile C code in C mode without issue. The issue, which they are technically correct about, is if code like Speedo's example were compiled in a C++ compilation unit, which may not be wise anyway, it would generate an error. For that scenario, there is a small amount of C code that would generate minor complaints within a C++ compilation unit, but proper organization of the project would eliminate that, primarily the separation of genuine C code and C++ code into separate compilation units.
Their point is that Objective-C doesn't alter C at all (the syntax of the Objective-C component is so entirely different there's no chance for collision). Speedo's and Lindley's example is one of a few such C constructs that would compile in Objective-C, but would fail in Objective-C++, exactly - I mean exactly - the same way it would in a mixed compilation of C and C++ code, where the C code is placed in C compilation units, and C++ code is placed in C++ compilation units. Some C constructs would fail if "mis" placed into C++ compilation units.
That's not guessing.
The article's point is misleading if technically accurate.
I would put it this way. The "objective" part is of such a unique syntax that it can be tacked on to C or C++ without interference with either. Most any compiler that accepts C++ code also has a C mode of operation which accepts compliant C code as is, without alteration, generating correct executables. It could be said they're trying point out you can't write C++ code when the compiler is in C mode, and you can't expect all C code to compile in C++ mode. They're happily ignoring the fact that these compilers will compile in C mode, and like a dishonest politician, trying to use that as a point of contention.
There's a boatload of C code that will compile in C++ mode, another boatload that will if very minor modifications are made, and some that would take some effort, but it's effort that's simply not required with any modern compiler.
I suppose they could wave a flag of victory if they're trying to somehow point out that there's two modes, C or C++, and not 4, C, Objective-C, C++ and Objective-C++ - the "objective" component doesn't require that the compiler break into these 4 modes.
The syntax is still ugly
Last edited by JVene; July 26th, 2009 at 11:07 PM.
If my post was interesting or helpful, perhaps you would consider clicking the 'rate this post' to let me know (middle icon of the group in the upper right of the post).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|