What is the difference between Definitions and Declarations in Compiler design?


It recognizes the code or data related to the name of the variable, function, class, etc. The definition is essentially needed by the compiler to designate the storage area for the declared entity. When a variable is defined it has an amount of memory that includes multiple bytes for that variable.

A function definition generates code for the function. It can define a program element only once in a program because the definition is a unique requirement of a program element. The relationship between declaration and definition can be one-to-many.


It can determine the names of the program including the name of a variable, function, namespace, classes, etc. No name can be utilized in a program without its declaration.

The program elements can be declared several times, with a different definition. Various declarations can only be produced when multiple declarations are formed using the exact format. The declaration is the medium of supporting perceptibility to the program element from the view of compilers.

Let us see the comparison between Definitions and Declarations.

The definition specifies attributes and causes storage allocation.
The declaration designates types and different attributes but does not generate a distribution of storage.
The data included in the definition is only used during translation. The language translator enters the data from the type definition into the table during translation and whenever the type name is referenced in a successive declaration, used the tabled data to create the suitable executable program for setting up and manipulating the desired information objects during execution.
The data included in the declaration of a variable is used mainly during translation to decide the storage representation for the information object and storage management and type checking objectives.
For a particular name, a C program can have only a single definition.
For a particular name, a C program can have various compatible declarations.
The type definition enables some elements of translation including deciding storage representations to be completed only once for a single type definition.
The type declaration determines storage representation many times for different declarations.
The inclusion of type definitions in a language does not generally modify the runtime organization of the language execution.
The inclusion of type definitions in a language may change the runtime organization of the language because they are used to set up the runtime data objects.