Sujet : Re: "A diagram of C23 basic types"
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 04. Apr 2025, 20:18:58
Autres entêtes
Organisation : None to speak of
Message-ID : <85zfgvivkt.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11
User-Agent : Gnus/5.13 (Gnus v5.13)
David Brown <
david.brown@hesbynett.no> writes:
[...]
It is easy to write code that is valid C23, using a new feature copied
from C++, but which is not valid C++ :
>
constexpr size_t N = sizeof(int);
int * p = malloc(N);
It's much easier than that.
int class;
Every C compiler will accept that. Every C++ compiler will reject
it. (I think the standard only requires a diagnostic, which can
be non-fatal, but I'd be surprised to see a C or C++ compiler that
generates an object file after encountering a syntax error).
Muttley seems to think that because, for example, "gcc -c foo.c"
will compile C code and "gcc -c foo.cpp" will compile C++ code,
the C and C++ compilers are the same compiler. In fact they're
distinct frontends with shared backend code, invoked differently
based on the source file suffix. (And "g++" is recommended for C++
code, but let's not get into that.)
For the same compiler to compile both C and C++, assuming you don't
unreasonably stretch the meaning of "same compiler", you'd have to
have a parser that conditionally recognizes "class" as a keyword or
as an identifier, among a huge number of other differences between
the two grammars. As far as I know, nobody does that.
You and I know he's wrong. Arguing with him is a waste of everyone's
time.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */