Sign in Join
Wiki copytemporary

Identifier

Deutsch · English · Français · Suomi · Русский

An identifier is a symbol used to unambiguously denote an object. Such objects could be for instance

Declaration

In Pascal an identifier has to be declared prior its first use. Depending on the object’s nature the identifier declaration is crafted in one manner or another, but the general scheme $(\text{identifier}, \text{object})$ stays the same (2-tuple [that means, it is ordered]).

An identifier has to consist of at least one ASCII letter or underscore. After the first character ASCII digits may follow, too. In the case of labels, pure numeric identifiers are allowed, too.

In Pascal identifiers are case-insensitive. Foo, fOO, and FoO identify the very same object. This rule applies only for Pascal code, though. Inside inline-assembler statements asm … end identifiers are case-sensitive and may have to adhere to different structures.

Identifiers must not be reserved words. However, since FPC retroactively declared some identifiers as reserved words, it introduced the &-escape to allow their usage as identifiers anyway. Note, that the set of reserved words depends on the active compiler compatibility mode.

Identifiers are only valid in the scope they were declared in. In other blocks a symbol may have a different meaning or hide an already declared identifier.

Example

pascal
program identifierDemo(input, output, stdErr);

const
    answer = 42;

var
    x: integer;

procedure foo;
begin
    x := answer;
end;

begin
    foo;
end.

This program contains the identifiers:

Significant characters

FPC considers up to 127 characters of an identifier as significant. A character being significant means, that only the first $n$ characters are actually considered while determining whether one object or another is being referred to.

It is allowed to write identifiers longer than 127 characters. However, if two objects are/ought to be referred by two identifiers that start off with the same 127 characters, the 128th and beyond characters are ignored. The compiler will fail with a duplicate declaration compile-time error.

Due to internal reasons, all words are capped to 255 characters, though. (This limit does not concern string literals, which are – mathematically speaking – objects.)

Historically, there were compilers that considered only the first eight characters as significant. This evoked very cryptic identifiers.

Choosing good identifiers

There are some considerations in picking a “good” identifier:

See also


From the Free Pascal wiki, page "Identifier", as it stood on 2021-07-04 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 1, last changed by WikiArchive .

Talk about this page

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