c - Can I rely on the include guards in standard headers -


I want to know that I can rely on the specific definitions of guards included in the standard headers. If I look at my system with Visual Studio, for example, that is defined in _STDINT in stdint.h My question is whether I get this #define In fact, it is safe for me to do something like this:

  #ifndef _STDINT typedef char int8_t; #endif  

I know that this might look stupid why not just say stdint.h included you? Well I am writing code which can be deployed to embedded targets, which can not be happy about the inclusion of some standard C header however, when I'm available, I want to be able to use them . Therefore, I want to select the file in which int main () is that I want to include stdint.h or not.

You can rely on any standard library header you specify to declare (and thereby No more). This means that:

  • If the feature is optional, then standard will specify a feature-test macro that you can check with #if or > #ifdef , tell you if it's available on your platform. As in CA11, threads.h is optional, so the standard specifies that __ STDC_NO_THREADS __ is defined by 1 if the header is not available.

  • If a feature is not optional, you can assume that it exists! If this is not present, the compiler does not correspond to the language version, and you can better expect that this material has been clearly heard in the document because you are in the implementation-defining area.

  • Many features are provided in the form of macros, or with associated macro definitions; So you can check the existence of independent features from the entire headers.

Therefore, in the case of stdint.h , there is no feature feature macro provided because the header is not optional. If this is not present, the compiler should actually be documented, and should not claim standard compliance. However, some features within stdint.h are optional, and therefore are separately testable with their associated macros. For example, the associated macro definitions describing their Max and Minimum values ​​are 7.20 (the exact-width integer type described in the code)> Int8_t and so on (and these macros are typically not should be defined if the types are not available), so that you can see the specific availability of int8_t by checking whether the INT8_MAX Is defined after.


Comments