View Single Post
BAILOPAN
Join Date: Jan 2004
Old 11-08-2014 , 17:35   Re: New API and Syntax
Reply With Quote #154

Hi All - I have some breaking changes to the transitional syntax. These should be the final breaking changes.

The position of brackets on a new-style declaration is now very important. When brackets occur after the name, they now indicate a fixed-length array, and require either an array initializer or constant sizes specified in every dimension.

If the brackets are before the name (between the name and type), they now specify an indeterminate/dynamic array - no fixed size may be specified, and an array initializer is not allowed (though that last restriction may change).

Finally, sizeof on an indeterminate array is now an error instead of a warning.

What does this mean? Here are some examples to show all the common transformations:
Code:
stock GetProperty(const String:name[], String:buffer[]) {   const String:PROP_PREFIX[] = "prop";   new new_name_size = sizeof(PROP_PREFIX) + strlen(name) + 1;   new String:new_name[new_buffer_size];   Format(new_name, new_name_size, "%s_%s", PROP_PREFIX, name);   ... }

In new-style syntax, this will now look like:
Code:
void GetProperty(const char[] name, char[] buffer) {   const char PROP_PREFIX[] = "prop";     int new_name_size = sizeof(PROP_PREFIX) + strlen(name) + 1;   char[] new_name = new char[new_name_size];   Format(new_name, new_name_size, "%s_%s", PROP_PREFIX, name); }

The major takeaway: brackets-after-name, must be fixed size; brackets-before-name, must be dynamic size. Code that specifies new-style arrays with trailing brackets, but no size, or a dynamic size, will no longer compile.

Full documentation and rationale here: https://wiki.alliedmods.net/SourcePa..._Syntax#Arrays
__________________
egg

Last edited by BAILOPAN; 11-08-2014 at 17:37.
BAILOPAN is offline