5 ms·
typeof is a GNU extension, but it (or an equivalent) is implemented in every compiler anyone actually uses. You can do it in C, you just can't do it in the par
by twtw 8y ago
typeof is a GNU extension, but it (or an equivalent) is implemented in every compiler anyone actually uses.
You can do it in C, you just can't do it in the part of C the standards committee has decided to standardize.
I'm not sure what the value is of defining C as standard C when loads of software has shipped for decades using this pattern.
- comex 8y ago...with the notable exception of MSVC.
- taneq 8y agoAnd there you have it. Purists claim C or C++ can't do X because it's UBH in the standard. Pragmatists know that C and (especially) C++ aren't languages on their own, while "gcc" and "MSVC++" are complete (and very similar) languages.
- adrianN 8y agoAnd careful people keep in mind that only what's defined in the standard can be expected to be true across compiler updates.
- AstralStorm 8y agoNot even that. Compilers had and have bugs.
- adrianN 8y agoIt's not a bug if it's UB. If the compiler behaves differently than the standard says it should you can file a bug.
- tom_ 8y agoThe compiler vendor can treat UB however they like. One option would be for them to specify that it does something in particular... (The C standard explicitly calls this out as a valid way of handling UB.)
- taneq 8y agoGood clarification, you really only know what you're going to get on (language, compiler, compiler version, platform).
- adrianN 8y agoYou also need to know the exact implementation of your compiler's optimizer, otherwise you don't know whether it's safe to change your program. Any change might give the optimizer enough information to unleash the nasal demons in previously cromulent code.
- twtw 8y agoSure, for UB. But extensions like typeof are different from UB. They have documented behavior, it is just documented by GNU instead of the C standards committee.
- taneq 8y agoAnd it's stuff like this which is making me increasingly uncomfortable with using C++ as my main language. Currently it looks like Rust is the most suitable replacement but I'm not sure if it's there yet.