What is the reason for underscore in C variable name definition?

前端 未结 3 595
忘掉有多难
忘掉有多难 2020-11-29 12:45

I am trying to understand when a developer needs to define a C variable with preceding \'_\'. What is the reason for it?

For example:

ui         


        
3条回答
  •  忘掉有多难
    2020-11-29 13:14

    Maybe this helps, from C99, 7.1.3 ("Reserved Identifiers"):

    • All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.

    • All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces.

    Moral: For ordinary user code, it's probably best not to start identifiers with an underscore.

    (On a related note, I think you should also stay clear from naming types with a trailing _t, which is reserved for standard types.)

提交回复
热议问题