Re: Using __STDC_VERSION__ macro

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 01/02/17 15:13, Mason wrote:
> On 01/02/2017 14:52, Jonathan Wakely wrote:
>> On 1 February 2017 at 13:49, Mason wrote:
>>> Hello,
>>>
>>> https://gcc.gnu.org/gcc-5/porting_to.html states
>>>
>>> "Typically, this macro is used as in the following:
>>>
>>>   #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
>>>     /* ... */
>>>   #else
>>>   # include <stdint.h>
>>>   #endif
>>> "
>>>
>>> I think it is unnecessary to test for the existence of __STDC_VERSION__
>>> because N1256 6.10.1p4 states
>>> "all remaining identifiers [...] are replaced with the pp-number 0"
>>>
>>> Therefore
>>> #if __STDC_VERSION__ < 199901L
>>> would work as expected, even when __STDC_VERSION__ is undefined.
>>> (As the constant-expression would be false.)
>>
>> But you'd get a warning with -Wundef
> 
> Right.
> 
> I'm not convinced by the usefulness of -Wundef, though.
> 
> I suppose its only use is catching typos such as
> 
> #define FOO 42
> #if GOO
> #endif
> 
> which would silently discard the conditional code.
> 

-Wundef is useful /precisely/ because it catches such mistakes.

The replacement of undefined identifiers with 0 in "#if " directives is,
IMHO, a particularly bad case of historical baggage.  Compilers can't
change that now, but I think it is a good idea to use -Wundef for your
own code.





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux