Difference between revisions of "@"
From Free Pascal wiki
Jump to navigationJump to search (http_s_ links to documentation, update links to documentation, add paragraph and example about {$typedaddress on}) |
m (crossref Pointer) |
||
Line 5: | Line 5: | ||
The address operator @ returns the address of a [[Variable|variable]], [[Procedure|procedure]] or [[Function|function]]. | The address operator @ returns the address of a [[Variable|variable]], [[Procedure|procedure]] or [[Function|function]]. | ||
− | Normally, the value <code>@</code> returns is an ''untyped'' pointer. | + | Normally, the value <code>@</code> returns is an ''untyped'' [[Pointer|pointer]]. |
If you are handling pointers a lot, and want to mitigate issues with passing references of wrong type's target, you have use the directive <code>{$typedaddress on}</code>. | If you are handling pointers a lot, and want to mitigate issues with passing references of wrong type's target, you have use the directive <code>{$typedaddress on}</code>. | ||
Revision as of 02:53, 31 January 2018
│
English (en) │
suomi (fi) │
français (fr) │
русский (ru) │
@
The address operator @ returns the address of a variable, procedure or function.
Normally, 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 use the directive {$typedaddress on}
.
Here some example to demonstrate, what produces with untyped pointers valid and functional code, but semantically outputs an erroneous result:
program typedAddress(input, output, stderr);
procedure incrementIntByRef(const ref: PByte);
begin
inc(ref^);
end;
var
foo: integer;
begin
foo := -1;
incrementIntByRef(@foo);
writeLn(foo);
end.
It should print 0
(zero), but prints -256
.
With {$typedaddress on}
compilation fails with an incompatible type error.