Skip to content

What's new

Zeex edited this page Apr 4, 2015 · 41 revisions

Table of Contents

Bug fixes

See Known compiler bugs for the full list of known bugs and their current status.

Features

Preprocessor directives

#pragma compat

Toggles compatibility mode on or off.

Note: this pragma will not change the value of __Pawn.

#pragma naked

Suppress the "must return a value" warning for a function.

This can be used on functions that don't have a return statement but still return a value, e.g. via #emit retn.

#pragma warning

This directive comes in two forms:

  • #pragma warning (enable|disable) XXX

Enable or disable a warning by its number.

Useful for hiding unwanted warnings that otherwise cannot be fixed.

  • #pragma warning (push|pop)

Save or restore the list of currently disabled warnings.

This can be used in conjuction with the previous form to toggle warnings for a piece of code:

#pragma warning push
#pragma warning disable XXX

// some code here
...

#pragma warning pop

#warning

Print a user warning.

This works similar to the #error directive. For example, compiling a file that contains

#warning Don't include this file

would result in

warning 237: user warning: Don't include this file

Built-in constants

__line

The built-in __line constant is set to the current line number.

Backported from Pawn 4.0.

Other features

Enums and sizeof in default arguments

When you have an enum with an array member

enum Foo {
    a,
    b[10]
};

new bar[100][Foo];

and you use it in a function that has a parameter with a default value equal to sizeof(other_parameter). For instance, in the following code:

f(x[], size = sizeof(x)) {
    #pragma unused x
    printf("size = %d", size); // size = 10
}

main() {
    f(bar[0][b]);
}

size would be set to the size of b, i.e. 10 cells (as you would expect) rather than 1 like with the old compiler.

Backported from Pawn 3.3.4058.

Progressive initializers for 2d arrays

Initialization of two-dimensional arrays can be continued with an ellips operator, similar to one-dimensional arrays. For example, the following code:

new a[5][10] = {{0, 1, 2, ...}, {0, 2, 4, ...}, ...};

is equivalent to:

new a[5][10] = {
    {0, 1, 2,  3,  4,  5,  6,  7,  8,  9},
    {0, 2, 4,  6,  8,  10, 12, 14, 16, 18},
    {0, 3, 6,  9,  12, 15, 18, 21, 24, 27},
    {0, 4, 8,  12, 16, 20, 24, 28, 32, 36},
    {0, 5, 10, 15, 20, 25, 30, 35, 40, 45}
};

Breaking changes

The following changes may break existing code (use -Z to disable them):

No automatic #include guards

The automatic generation of _inc_XXX symbols was disabled due to their inconsistent behavior across platforms (Linux vs. Windows). See #6 for details.

In order to make it possible to include the same file multiple times without getting compile errors you can add something like this to your include file:

#if defined YOUR_INCLUDE_INC
  #endinput
#endif
#define YOUR_INCLUDE_INC

// code goes here

New __Pawn value

The value of the built-in __Pawn constant was changed from 0x0302 to 0x030A (#5). This allows you to do detect this compiler at compile time:

#if __Pawn == 0x030A
  // some code here
#else
  // alternative code
#endif

Other changes

Version string

The compiler version string that can be seen in compile output and in file properties on Windows now ends with .samp. This helps distinguish this compiler from the official one.

Clone this wiki locally