Forum > General

Assigning result of a function of type array

<< < (3/3)

Warfley:
As thaddy nicely demonstrated, a typed const is not a constant but a writable const. An object with static lifetime but local scope, meaning a global variable only accessible to the function in which it is declared. It's very useful but syntactically confusing.

If you want real consts you need to set the writableconst or J Compiler Switch off

Thaddy:
Two other remarks:
Real consts are if possible directly substituted by the compiler, so not stored at all, or complex consts stored in the .rodata section.
Typed consts in {$writeableconst on mode} are stored as global vars with local scope. Warfley added more explanation.
Typed consts in {$writeableconst off} mode are always stored in the .rodata section.
.rodata is read-only data.

PascalDragon:

--- Quote from: Thaddy on September 15, 2024, 07:41:50 am ---Typed consts in {$writeableconst off} mode are always stored in the .rodata section.
.rodata is read-only data.

--- End quote ---

This depends on the used assembler. If the GNU assembler is used then on some platforms it will be .rodata, but on others it will be .data due to issues with relocations (see comment in TGNUAssembler.sectionname() in compiler/aggas.pas).

Thaddy:
That is an interesting thing I did not know about yet. But at least it is the intention that it is stored in a read-only section. Thanks for that info.
I only tested windows 10/11 64 and linux 64 both on amd64.

Navigation

[0] Message Index

[*] Previous page

Go to full version