C Declaraction vs Definition
In C, there is a difference between declaration and definition.
Declaration (C99, 6.7)
A declaration specifies the interpretation and attributes of a set of identifiers.
Definition (C99, 6.7)
A definition of an identifier is a declaration for that identifier that:
- for an object, causes storage to be reserved for that object;
- for a function, includes the function body
- for an enumeration constant or typedef name, is the (only) declaration of the identifier.
Tentative definition (C99, 6.9.2)
A declaration of an identifier for an object that has file scope without an initializer, and without a storage-class specifier or with the storage-class specifier static, constitutes a tentative definition
In a nutshell
Code | Scope (C99, 6.2.1) | Declaration | Definition | Tentative Definition |
---|---|---|---|---|
int x; |
File | Yes | No | Yes |
static int x; |
File | Yes | No | Yes |
int x = 10; |
File | Yes | Yes | No |
extern int i; |
File | Yes | No | No |
int x = 10; |
Block | Yes | Yes | No |
void foo( void ); |
File | Yes | No | No |
void foo( void ) {} |
File | Yes | Yes | No |
void foo( void ); void foo() {} |
File | Yes void foo( void ); |
Yes void foo( void ) {} |
No |
void foo( void ) { int x;} |
File | Yes | Yes | No |