Sujet : Re: "A diagram of C23 basic types"
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.cDate : 04. Apr 2025, 18:25:59
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vsp4n7$3u65o$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 04/04/2025 18:12,
Muttley@dastardlyhq.com wrote:
On Fri, 4 Apr 2025 17:28:42 +0200
David Brown <david.brown@hesbynett.no> gabbled:
On 04/04/2025 16:02, Muttley@DastardlyHQ.org wrote:
You are using a combined C and C++ compiler in C mode, and it compiles
the C program as C. In that sense, most C++ compilers are also C
>
Err yes! Thats the whole point!!
>
>
Then if we back up the thread to where you said C programmers could just use a C++ compiler to get new features, you were clearly wrong. Of course, we all knew you were wrong already, the only question was in what way you were wrong.
You think having to add an extra cast is so onorous that it doesn't count
as C any more? Any decent C dev would add it by default. Obviously I don't
include you in that grouping.
Do you understand the concept of "example" ?
Chris (not me) gave an /example/ of code that is valid C, but not valid C++. There are many other things that he could have picked - this is just a clear and simple one.
And yes, I know that adding a cast here is easy. And I know that /some/ C developers do that anyway - I am one of them, partly because C++ compatibility in my C code is sometimes important for my work. (I very rarely have dynamic memory in my code in the first place.) Equally, I know that many C developers do /not/ put in such a cast, and feel that it is a bad thing to have which could hide certain potential errors from compilers or linters.
Other cases of C / C++ incompatibility that would cause a lot more inconvenience would be the use of things like "new" as identifiers, type-punning unions (which are UB in C++), compound literals, designated initialisers (even with C++20 support, there are plenty of differences), etc.
It is certainly the case that most normal, well-written C is mostly compatible with C++ and with the same semantics. But "most" is not sufficient if you want to compile your C code as though it were C++.