MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | NAME |
| 2 | block |
| 3 | |
| 4 | DESCRIPTION |
| 5 | A block is a special statment, that begins with '{', contains |
| 6 | a list of statements, and ends with '}'. |
| 7 | |
| 8 | The block may define local variables. If for a variable no |
| 9 | initialisation is given, the variable is initialised to 0 every |
| 10 | time the block is entered. Otherwise, the initialisation |
| 11 | expression is evaluated and its result assigned to the variable |
| 12 | everytime the block is entered. |
| 13 | |
| 14 | Example definitions are: |
| 15 | |
| 16 | int i; |
| 17 | int j = 3; |
| 18 | int k = 3 * j, l; |
| 19 | |
| 20 | Here, i and l are both initialised to 0; j is initialised |
| 21 | to 3, and k is initialised to 9 (3 * j). |
| 22 | |
| 23 | Local variables defined in a block are visible only until the |
| 24 | end of the block. Definitions in an inner block hide definitions in |
| 25 | outer blocks. |
| 26 | |
| 27 | HISTORY |
| 28 | Up to 3.2.7 local variables were visible (from their point of |
| 29 | definition) in the whole function. That is, code like |
| 30 | |
| 31 | do { |
| 32 | int res; |
| 33 | |
| 34 | res = ... |
| 35 | } while (res == 5); |
| 36 | write(res); |
| 37 | |
| 38 | was perfectly legal. It is no longer, as 'res' ceases to exist |
| 39 | with the closing '}' of the while(). |
| 40 | |
| 41 | Up to 3.5.0 you could get this old behaviour back with the |
| 42 | #pragma no_local_scopes and switch it off again with |
| 43 | #pragma local_scopes. |
| 44 | |
| 45 | Since 3.5.0 it is not possible to disable the local scope behaviour. |
| 46 | |
| 47 | Up to 3.2.8, local variables could not be initialised in their |
| 48 | definition. |