Sujet : Re: C23 thoughts and opinions
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 26. May 2024, 22:53:27
Autres entêtes
Organisation : None to speak of
Message-ID : <87wmngz454.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
jak <
nospam@please.ty> writes:
[...]
I really wrote that something similar (similar != equal) did g++ and
that, if you write c++ code in a file with the .c extension, the g++
compile it. I never wrote that it was automatically recognized.
In addition, you just explained why g++ compile a .c that contains c++
code. I don't understand: no what?
You previously made statements that I interpreted as claims that some
compilers will determine which language to compile based on the
*content* of the source file. (I think you now acknowledge that that's
not the case. If so, I'm not going to bother going back and rereading
your previous posts.)
g++ does not do that, nor does any other compiler command I've heard of.
For the gcc collection (which includes commands "gcc" and "g++"), the
determination of which language to process is based on a combination of
the file name suffix (".c" vs. ".C" or ".cpp", etc.), the driver command
being invoked ("gcc" vs. "g++"), and additional command-line options
("-x c"). In no case does the content affect that determination. If
the driver command has determined that the source should be compiled as
C++, a syntax error or other recognition of C source code will never
cause it to backtrack and try to compile the source as C.
$ cat c.c
int class;
$ g++ -c c.c
c.c:1:10: error: expected identifier before ‘;’ token
1 | int class;
| ^
[snip]
Some potential sources of confusion:
The resolution rules for gcc and g++ are subtly different, probably for
historical reasons (gcc was originally for C only). Other drivers like
gfortran and gdc may or may not behave entirely consistently; I haven't
checked.
The ".C" suffix is recognized as C++ source, but can cause confusion on
systems with case-insensitive file names.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */