Wiki copymirror

This is a mirror of the wiki at pascal.chat. Editing, history and sign-in are there.

@

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

@

The address operator @ returns the address of an identifier that is associated with an address (usually a variable or routine, but also a label).

Normally, what the value @ returns is an untyped pointer. If you are handling pointers a lot, and want to mitigate issues with passing references of wrong type’s target, you have to use the directive {$typedAddress on}.

Here is an example to demonstrate what produces with untyped pointers valid and functional code, but semantically outputs an erroneous result:

pascal
program untypedAddressDemo(input, output, stderr);
    
    procedure incrementIntByRef(const ref: PByte);
    begin
        inc(ref^);
    end;
    
    var
        foo: integer;
    begin
        foo := -1;
        incrementIntByRef(@foo);
        writeLn(foo);
    end.

It was intended that 0 (zero) gets printed, but the program prints -256 instead. With {$typedAddress on} compilation fails with an incompatible type error. You usually want the latter behavior (compile-time error) instead of wasting time with hours of debugging.

other remarks

read more

navigation bar: topic: Pascal symbols

single characters: + (plus) • - (minus) • * (asterisk) • / (slash) • = (equal) • > (greater than) • < (less than) • . (period) • : (colon) • ; (semi colon) • ^ (hat) • @ (at) • $ (dollar sign) • & (ampersand) • # (hash) • ' (single quote)

character pairs: <> (not equal) • <= (less than or equal) • := (becomes) • >= (greater than or equal) • >< (symmetric difference) • // (double slash)


From the Free Pascal wiki, page "@", as the Internet Archive kept it on 2025-03-17, last changed on 2024-07-18. 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 4, last changed by WikiArchive .