C Declaraction vs Definition

February 3, 2014

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:

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

Discussion, links, and tweets

I'm a developer at IO Stark.