简体   繁体   中英

stdint.h and C99

I read in the C99 standard that stdint.h is part of the C standard library.

Do I read correctly that, if I test for C99 compliance, using:

defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)

that means stdint.h is supposed to be available?

Case in point: can I consider an environment which pretends to be C99 compliant but doesn't provide stdint.h to be at odds with its own compliance statement, hence buggy?

Edit : for the curious ones, the system in question is OpenVMS with HP C Compiler (not gcc, which on openVMS does provide stdint.h ). So according to answers and comments received so far, I have to consider this implementation (which pretends to be C99) as buggy. For more details : https://groups.google.com/forum/#!topic/comp.os.vms/Bnh3tIOc7bo%5B101-125%5D

Yes.

Incidentally, undefined symbols expand to 0 in preprocessor expressions, so you could just write:

#if __STDC_VERSION__ >= 199901L

On the other hand, an implementation that doesn't claim to conform to C99 (or C11) might still support <stdint.h> as an extension.

stdint.h is one of the few headers that any conforming implementation is forced to implement. Even various obscure embedded systems compilers have to do this. See normative text C11 chapter 4/6:

A conforming hosted implementation shall accept any strictly conforming program. A conforming freestanding implementation shall accept any strictly conforming program in which the use of the features specified in the library clause (clause 7) is confined to the contents of the standard headers <float.h>, <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, <stdint.h>, and <stdnoreturn.h> .

So you can test for __STDC_VERSION__ >= 199901L indeed and then the header must be available. Note that there is no such requirement for inttypes.h .

Case in point: can I consider an environment which pretends to be C99 compliant but doesn't provide stdint.h to be at odds with its own compliance statement (and hence buggy)?

Yes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM