4

In the C11 standard is written that compilers should provide some macros to test for optional feature presence. In what headers do I find them?

For example where is located __STDC_NO_VLA__?

With GCC, i.e., if I try to find __STDC_NO_COMPLEX__ into complex.h I don't find it there...

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
xdevel2000
  • 20,780
  • 41
  • 129
  • 196

2 Answers2

7

They are not defined in any header, a compiler will define them itself.

You can dump all of the preprocessor defines. For example for gcc write:

gcc -dM -E - < /dev/null

For example for me:

bob@bob-fedora:~/trunk/software$ gcc --version
gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8)
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

bob@bob-fedora:~/trunk/software$ gcc -std=gnu11 -dM -E - < /dev/null | grep STDC
#define __STDC_HOSTED__ 1
#define __STDC_UTF_16__ 1
#define __STDC_VERSION__ 201112L
#define __GNUC_STDC_INLINE__ 1
#define __STDC_UTF_32__ 1
#define __STDC__ 1

In the example you gave, __STDC_NO_VLA__ the presence of this means that the compiler does not supported variable length arrays. You could write:

#ifdef __STDC_NO_VLA__
#error Your compiler does not support VLAs! Please use a supported compiler.
#endif

Or

#ifndef __STDC_NO_VLA__
// code using variable length arrays
#else
// fallback code for when they are not supported
#endif
robbie_c
  • 2,428
  • 1
  • 19
  • 28
1

if STDC_NO_COMPLEX is defined, it indicates that there is is no complex.h

STDC_NO_COMPLEX is defined by the compiler, not by header file

source: http://en.cppreference.com/w/c/numeric/complex

flotto
  • 535
  • 5
  • 17
  • Ironically, the C11 standard Annex B says that STDC_NO_COMPLEX should be located in complex.h, which doesn't make any sense. Seems to be an error in the (non-normative) Annex B. – Lundin Apr 07 '14 at 14:26