• No results found

⋄ pawn lacks the typing mechanism of C.pawnis an “integer-only” variety

of C; there are no structures or unions, and floating point support must be implemented with user-defined operators and the help of native functions.

⋄ The accepted syntax for rational numbers is stricter than that of floating point values in C. Values like “.5” and “6.” are acceptable in C, but in pawn one must write “0.5” and “6.0” respectively. In C, the decimal

period is optional if an exponent is included, so one can write “2E8”;pawn

does not accept the upper case “E” (use a lower case “e”) and it requires the decimal point: e.g. “2.0e8”. See page 98for more information. ⋄ pawn does not provide “pointers”. For the purpose of passing function

arguments by reference,pawnprovides a “reference” argument, (page 70).

The “placeholder” argument replaces some uses of the NULL pointer (page 74).

⋄ Numbers can have hexadecimal, decimal or binary radix. Octal radix is not supported. See “Constants” onpage 97. Hexadecimal numbers must start with “0x” (a lower case “x”), the prefix “0X” is invalid.

⋄ Escape sequences (“\n”, “\t”, etc.) are the same, except for “\ddd” where “ddd” represent three decimal digits, instead of the octal digits that C/C++ uses. The backslash (“\”) may be replaced with another symbol; see #pragma ctrlcharon page 119 —notably, previous versions of pawn used the caret (“^”) as the escape character.

⋄ Cases in a switch statement are not “fall through”. Only a single in- struction may (and must) follow each case label. To execute multiple instructions, you must use a compound statement. The default clause of a switch statement must be the last clause of the switch statement. More on page 114. In C/C++, switch is a “conditional goto”, akin to Fortran’s calculated labels. In pawn,switchis a structured “if”.

⋄ A breakstatement breaks out of loops only. In C/C++, thebreak state- ment also ends a case in a switch statement. Switch statements are implemented differently in pawn (see page 114).

⋄ pawn supports “array assignment”, with the restriction that both arrays

must have the same size. For example, if “a” and “b” are both arrays with 6 cells, the expression “a = b” is valid. Next to literal strings,pawn

also supports literal arrays, allowing the expression “a = {0,1,2,3,4,5}” (where “a” is an array variable with 6 elements).

⋄ definedis an operator, not a preprocessor directive. Thedefinedopera- tor inpawnoperates on constants (declared withconst), global variables,

local variables and functions.

⋄ The sizeofoperator returns the size of a variable in “elements”, not in “bytes”. An element may be a cell or a sub-array. Seepage 108for details. ⋄ The empty instruction is an empty compound block, not a semicolon (page

111). This modification avoids a frequent error.

⋄ The compiler directives differ from C’s preprocessor commands. Notably, the#definedirective is incompatible with that of C/C++, and#ifdefand

#ifndef are replaced by the more general#if directive (see “Directives” on page 116). To create numeric constants, see also page 101; to create string constants, see alsopage 92.

⋄ Text substitutions (preprocessor macros; see the #define directive) are not matched across lines. That is, the text that you want to match and replace with a #definemacro must appear on a single line.

⋄ A division is carried out in such a way that the remainder after division has (or would have) the same sign as the denominator. For positive de- nominators, this means that the direction for truncation for the operator “/” is always towards the smaller value, where -2 is smaller than -1, and that the “%” operator always gives a positive result —regardless of the sign of the numerator. See page 103.

⋄ There is no unary “+” operator, which is a “no-operation” operator any- way.

⋄ Three of the bitwise operators have different precedence than in C. The precedence levels of the “&”, “^” and |operators is higher than the rela- tional operators (Dennis Ritchie explained that these operators got their low precedence levels in C because early C compilers did not yet have the logical “&&” and||operators, so the bitwise “&” and|were used instead). ⋄ The “extern” keyword does not exist inpawn; the current implementation

of the compiler has no “linking phase”. To create a program from several source files, add all source files the compilers command line, or create one main project script file that “#include’s” all other source files. Thepawn

compiler can optimize out functions and global variables that you do not use. See pages 61 and83 for details.

⋄ The keyword const in pawn implements the enum functionality from C,

see page 101.

⋄ In most situations, forward declarations of functions (i.e., prototypes) are not necessary. pawnis a two-pass compiler, it will see all functions on the

first pass and use them in the second pass. User-defined operators must be declared before use, however.

If provided, forward declarations must match exactly with the function definition, parameter names may not be omitted from the prototype or differ from the function definition. pawn cares about parameter names

in prototypes because of the “named parameters” feature. One uses pro- totypes to call forwardly declared functions. When doing so with named parameters, the compiler must already know the names of the parame- ters (and their position in the parameter list). As a result, the parameter names in a prototype must be equal to the ones in the definition.

Assorted tips