Include guard conventions in C

前端 未结 2 1977
广开言路
广开言路 2020-12-10 14:36

What is the conventional way to set up your include guards? I usually write them as (for example.h):

#ifndef _EXAMPLE_H_
#define _EXAMPLE_H_
#include \"exam         


        
2条回答
  •  独厮守ぢ
    2020-12-10 15:12

    There is no absolute requirement as to how include guards are named. It does not have to match the header name. I have seen (and used myself) some that use a UUID, basically composed of a randomly generated hexadecimal string.

    Technically as KingsIndian said, identifiers beginning with underscores are reserved:

    The rules, paraphrased from ANSI Sec. 4.1.2.1, are:

    1. All identifiers beginning with an underscore followed
       by an upper-case letter or another underscore are always
       reserved (all scopes, all namespaces).
    2. All identifiers beginning with an underscore are reserved
       for ordinary identifiers (functions, variables, typedefs, enumeration
       constants) with file scope.
    ...
    

    comp.lang.c FAQ list · Question 1.29

    Maybe the new ISO C11 (?) standard relaxes these rules, but that's been the bottom line for a while.

提交回复
热议问题