liveBook · Manning

Identifier

As explained in Modern C

An identifier is a C name assigned to a program entity such as an object, type alias, function, or constant.

int main(void);
double A[5];
size_t i;


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":3}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":8}],[{\"line\":0,\"ch\":9},{\"line\":0,\"ch\":13}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":6}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":6}]]"}
!@%STYLE%@!

Each declaration gives an identifier and associated properties: main names a function, A an array of five doubles, and i an object of type size_t. section 2.2

An identifier is a name given to an entity in a C program. Identifiers can name objects, type aliases, functions, and constants. For example, printf names a function, size_t names a type alias, and EXIT_SUCCESS names a constant. section 2.1

A declaration tells the compiler what an identifier represents and specifies its properties. Keywords differ: they are predefined by the language and cannot be declared or redefined. Takeaway: distinguish an object from its identifier, its type, and its current value. section 2.2

Identifier visibility begins at its declaration and is limited by its scope. A declaration in a subordinate scope can shadow an identifier with the same name. The object named by the shadowed identifier can still be accessible by other means. section 13.2

Listing 13.1. An example of shadowing with local variables
 1     void squareIt(double* p) {
 2       *p *= *p;
 3     }
 4     int main(void) {
 5     double x = 35.0;
 6     double* xp = &x;
 7     {
 8       squareIt(&x);  /* Refers to double x */ 
 9       ...
10       int x = 0;     /* Shadow double x */ 
11       ...
12       squareIt(xp);  /* Valid use of double x */ 
13       ...
14     }
15     ...
16     squareIt(&x);    /* Refers to double x */ 
17     ...
18   }


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":1},{\"line\":0,\"ch\":2}],[{\"line\":9,\"ch\":0},{\"line\":9,\"ch\":1}],[{\"line\":10,\"ch\":0},{\"line\":10,\"ch\":1}],[{\"line\":11,\"ch\":0},{\"line\":11,\"ch\":1}],[{\"line\":12,\"ch\":0},{\"line\":12,\"ch\":1}],[{\"line\":13,\"ch\":0},{\"line\":13,\"ch\":1}],[{\"line\":14,\"ch\":0},{\"line\":14,\"ch\":1}],[{\"line\":15,\"ch\":0},{\"line\":15,\"ch\":1}],[{\"line\":16,\"ch\":0},{\"line\":16,\"ch\":1}],[{\"line\":17,\"ch\":0},{\"line\":17,\"ch\":1}],[{\"line\":0,\"ch\":7},{\"line\":0,\"ch\":11}],[{\"line\":3,\"ch\":16},{\"line\":3,\"ch\":20}],[{\"line\":0,\"ch\":21},{\"line\":0,\"ch\":27}],[{\"line\":4,\"ch\":7},{\"line\":4,\"ch\":13}],[{\"line\":5,\"ch\":7},{\"line\":5,\"ch\":13}],[{\"line\":7,\"ch\":37},{\"line\":7,\"ch\":43}],[{\"line\":9,\"ch\":34},{\"line\":9,\"ch\":40}],[{\"line\":11,\"ch\":40},{\"line\":11,\"ch\":46}],[{\"line\":15,\"ch\":37},{\"line\":15,\"ch\":43}],[{\"line\":1,\"ch\":1},{\"line\":1,\"ch\":2}],[{\"line\":11,\"ch\":1},{\"line\":11,\"ch\":2}],[{\"line\":2,\"ch\":1},{\"line\":2,\"ch\":2}],[{\"line\":4,\"ch\":18},{\"line\":4,\"ch\":19}],[{\"line\":12,\"ch\":1},{\"line\":12,\"ch\":2}],[{\"line\":3,\"ch\":1},{\"line\":3,\"ch\":2}],[{\"line\":13,\"ch\":1},{\"line\":13,\"ch\":2}],[{\"line\":3,\"ch\":7},{\"line\":3,\"ch\":10}],[{\"line\":9,\"ch\":9},{\"line\":9,\"ch\":12}],[{\"line\":3,\"ch\":11},{\"line\":3,\"ch\":15}],[{\"line\":0,\"ch\":7},{\"line\":0,\"ch\":11}],[{\"line\":3,\"ch\":16},{\"line\":3,\"ch\":20}],[{\"line\":4,\"ch\":1},{\"line\":4,\"ch\":2}],[{\"line\":14,\"ch\":1},{\"line\":14,\"ch\":2}],[{\"line\":0,\"ch\":21},{\"line\":0,\"ch\":27}],[{\"line\":4,\"ch\":7},{\"line\":4,\"ch\":13}],[{\"line\":5,\"ch\":7},{\"line\":5,\"ch\":13}],[{\"line\":7,\"ch\":37},{\"line\":7,\"ch\":43}],[{\"line\":9,\"ch\":34},{\"line\":9,\"ch\":40}],[{\"line\":11,\"ch\":40},{\"line\":11,\"ch\":46}],[{\"line\":15,\"ch\":37},{\"line\":15,\"ch\":43}],[{\"line\":5,\"ch\":1},{\"line\":5,\"ch\":2}],[{\"line\":15,\"ch\":1},{\"line\":15,\"ch\":2}],[{\"line\":0,\"ch\":21},{\"line\":0,\"ch\":27}],[{\"line\":4,\"ch\":7},{\"line\":4,\"ch\":13}],[{\"line\":5,\"ch\":7},{\"line\":5,\"ch\":13}],[{\"line\":7,\"ch\":37},{\"line\":7,\"ch\":43}],[{\"line\":9,\"ch\":34},{\"line\":9,\"ch\":40}],[{\"line\":11,\"ch\":40},{\"line\":11,\"ch\":46}],[{\"line\":15,\"ch\":37},{\"line\":15,\"ch\":43}],[{\"line\":6,\"ch\":1},{\"line\":6,\"ch\":2}],[{\"line\":16,\"ch\":1},{\"line\":16,\"ch\":2}],[{\"line\":7,\"ch\":1},{\"line\":7,\"ch\":2}],[{\"line\":17,\"ch\":1},{\"line\":17,\"ch\":2}],[{\"line\":8,\"ch\":1},{\"line\":8,\"ch\":2}],[{\"line\":9,\"ch\":0},{\"line\":9,\"ch\":2}],[{\"line\":3,\"ch\":7},{\"line\":3,\"ch\":10}],[{\"line\":9,\"ch\":9},{\"line\":9,\"ch\":12}],[{\"line\":10,\"ch\":0},{\"line\":10,\"ch\":2}],[{\"line\":11,\"ch\":0},{\"line\":11,\"ch\":2}],[{\"line\":12,\"ch\":0},{\"line\":12,\"ch\":2}],[{\"line\":13,\"ch\":0},{\"line\":13,\"ch\":2}],[{\"line\":14,\"ch\":0},{\"line\":14,\"ch\":2}],[{\"line\":15,\"ch\":0},{\"line\":15,\"ch\":2}],[{\"line\":16,\"ch\":0},{\"line\":16,\"ch\":2}],[{\"line\":17,\"ch\":0},{\"line\":17,\"ch\":2}]]"}
!@%STYLE%@!

The inner int x shadows the outer double x, but squareIt can still use the outer object through the previously saved pointer xp. section 13.2

Preprocessor conditions have a special rule: an unknown identifier evaluates to 0. For example, #if !__STDC_LIB_EXT1__ can be evaluated even when that identifier is unknown. section 8.1.5

Choose a consistent naming policy and expose as few names as possible. Identifiers visible in headers must conform to naming restrictions; reserved names and macros can cause conflicts that emerge only after a change in platform or compiler. section 9.2

1   double memory_sum(size_t N, size_t I, double strip[N][I]);
N is a capitalized identifier, and thus your collaborator could be tempted to define a macro N as a big number.
I is used for the root of – 1 as soon as someone includes complex.h.
The identifier strip might be used by a C implementation for a library function or macro.
The identifier memory_sum might be used by the C standard for a type name in the future.


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":1}],[{\"line\":2,\"ch\":28},{\"line\":2,\"ch\":29}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":10}],[{\"line\":0,\"ch\":22},{\"line\":0,\"ch\":28}],[{\"line\":0,\"ch\":22},{\"line\":0,\"ch\":28}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":10}]]"}
!@%STYLE%@!

This function declaration illustrates possible collisions between parameter names, macros, and names that an implementation or future standard might use. section 9.2

How Modern C covers it

How deep it goes
Explains identifier roles, declarations, scope, shadowing, preprocessor conditions, and naming conflicts through examples.
Examples
Uses function and array declarations, a shadowed variable accessed through a pointer, and a header declaration with potential name collisions.
What you can do after
Evaluate and understand what identifiers represent, where names are visible, and how naming conflicts can arise.
How it connects
Connects identifiers with declarations, types, scope, shadowing, macros, and reserved names.

Also explained in

Compare how 5 books explain identifier →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.