mirror of
https://github.com/ldmud/ldmud
synced 2026-08-12 14:26:05 -04:00
Variables defined in a block will always cease to exist after the blocks end. (prolang.y, lex.c) git-svn-id: svn://svn.bearnip.com/ldmud/trunk@2867 56160b6e-f8f8-0310-bd54-bccebfe6a2f2
48 lines
1.5 KiB
Text
48 lines
1.5 KiB
Text
NAME
|
|
block
|
|
|
|
DESCRIPTION
|
|
A block is a special statment, that begins with '{', contains
|
|
a list of statements, and ends with '}'.
|
|
|
|
The block may define local variables. If for a variable no
|
|
initialisation is given, the variable is initialised to 0 every
|
|
time the block is entered. Otherwise, the initialisation
|
|
expression is evaluated and its result assigned to the variable
|
|
everytime the block is entered.
|
|
|
|
Example definitions are:
|
|
|
|
int i;
|
|
int j = 3;
|
|
int k = 3 * j, l;
|
|
|
|
Here, i and l are both initialised to 0; j is initialised
|
|
to 3, and k is initialised to 9 (3 * j).
|
|
|
|
Local variables defined in a block are visible only until the
|
|
end of the block. Definitions in an inner block hide definitions in
|
|
outer blocks.
|
|
|
|
HISTORY
|
|
Up to 3.2.7 local variables were visible (from their point of
|
|
definition) in the whole function. That is, code like
|
|
|
|
do {
|
|
int res;
|
|
|
|
res = ...
|
|
} while (res == 5);
|
|
write(res);
|
|
|
|
was perfectly legal. It is no longer, as 'res' ceases to exist
|
|
with the closing '}' of the while().
|
|
|
|
Up to 3.5.0 you could get this old behaviour back with the
|
|
#pragma no_local_scopes and switch it off again with
|
|
#pragma local_scopes.
|
|
|
|
Since 3.5.0 it is not possible to disable the local scope behaviour.
|
|
|
|
Up to 3.2.8, local variables could not be initialised in their
|
|
definition.
|