Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


External and tentative definitions in C

Adnan Abbas

External definition

Every C program contains a translation unit (a source file with all the #includes after the preprocessor ). There are multiple declarations in the translation unit, which declare functions and objects with external linkage. These declarations are called external declarations because they appear outside the scope of any function.

This is shown below:

extern int n; //external declaration with external linkage
static int q = 1; // external definition with internal linkage
int f(void){ //external definition with external linkage
int a = 1; //non-external

The static keyword implies internal linkage because it is visible only in its object file and remains in memory while the program runs.

Tentative definition

A tentative definition is any external data declaration that has no initializer and storage class specifier. It may or may not be a definition depending on if an actual external definition is found earlier or later in the translation unit. It becomes a full definition if we reach the end of the translation unit and no definition has appeared with an initializer for the identifier.

We can see this here:

int i1 = 10;         /* definition, external linkage */
static int i2 = 20;  /* definition, internal linkage */
int i3;              /* tentative definition, external linkage */

int i1;              /* valid tentative definition */
int i2;              /* not legal, linkage disagreement with previous */

In cases where there are no definitions found in the same translation unit, then the tentative definition is initialized by 0.




Adnan Abbas
Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring