Sign in Join
Wiki copytemporary

Declaration

A declaration introduces the compiler to new identifiers. It is an agreement between the programmer and compiler, that a certain symbol henceforth has a fixed meaning.

characteristics

Declarations do not have any (explicit) impact on a compiled program: For example, a declaration of a variable informs the compiler about a new identifier associated with a data type. However, neither the variable’s name, nor the data type are stored in the compiled binary file.

Nevertheless, implicitly the compiler reserves enough memory and ensures only legal operations are performed in compliance with the data type. Thus declarations ensure the compiler can process the source code.

types

Pascal knows following types of declarations:

difference to definitions

Declarations merely tell the compiler “there is something”. In contrast to that, definitions elaborate what “something” is. All definitions will (eventually) change the program state. Declarations do not change the program state.

   systemCrash;

Their definition, i. e. actually associating this identifier with an address, occurs later in the source code:

pascal
begin
    ???
    if somethingIsWrong then
    begin
        goto systemCrash;
    end;
    ???
systemCrash:
    ???

   answer = 42;

the information “answer is an integer constant” is the declaration. The information “answer equals 42” is the definition. The same applies to resource strings.

   point = record
           x, y: integer;
       end;

The definition of point is invisible: Which operations are allowed on point is not written in this piece of code. Nevertheless, the assignment of a point value to a point variable works out of the box, and further operations on point can be defined using operator overloading.

In summary, breach of agreed declarations cause compile-time errors, whereas wrong definitions cannot be caught by the compiler.


From the Free Pascal wiki, page "Declaration", as it stood on 2021-08-12 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.