Sign in Join
Wiki copytemporary

Addr

Deutsch · English

Addr is a compiler intrinsic behaving like a unary function returning the address of an object (if such exits). It is equivalent to the @ address operator, however, addr always returns an untyped pointer (since FPC 2.6.0). This behavior is compliant to Borland Pascal’s definition of the addr function, where this function originally comes from.

In Pascal-XSC, the loc function is the same as addr presented here.

usage

Addr is used just like every other function.

pascal
program addrDemo(input, output, stdErr);
var
    p: pointer;
begin
    p := addr(p);
    writeLn('Pointer p is located at ', sysBackTraceStr(p), '.');
end.

Addr can only be used on objects that have an address, that means reserve memory. The following objects do not have an address, thus addr cannot be used on them:

In case of types, the typeInfo compiler intrinsic has to be used in order to obtain a reference to RTTI.

application

Addr primarily exists for compatibility with code that was written for/with Borland Pascal. The @‑address operator (in conjunction with {$typedAddress on}) should be preferred, since it can return typed addresses. This will prevent some programming mistakes.

Also, in {$mode FPC} and {$mode objFPC} the @‑address operator has to be used to assign values to procedural values (unless {$modeSwitch classicalProcVars+} is set). In {$mode TP} and {$mode Delphi}, however, no operator at all may be used.

Last but not least, in asm blocks, addr cannot be used to obtain addresses of labels, but @ can.

see also


From the Free Pascal wiki, page "Addr", as it stood on 2024-02-29 after a change by Chernov, 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.