18.05.2013, 10:04
You cannot simply do something like for example
since macros are basicly text replacements and, if you try to use such macro twice in your script
becomes
will give you compiling errors, like that you've not declared the size of a "cchar" array and redeclaration of a "cchar" array.
pawn Код:
#define strncpy(%0,%1,%2,%3) \
new cchar[] \
;strmid(char,%1,0,((%2)-1)) \
;strdel(char,%2,strlen(char)) \
;strcat((%0[0] = '\0', %0),char,%3)
pawn Код:
public someCallback()
{
new some_array[4], some_array_2[4];
strncpy(some_array, "foo", 2, sizeof some_array); // not the same "sizeof" we know from C/C++
strncpy(some_array_2, "bar", 2, sizeof some_array_2);
}
pawn Код:
public someCallback()
{
new some_array[4], some_array_2[4];
new cchar[];
strmid(char, "foo",0,(( 2)-1));
strdel(char, 2,strlen(char));
strcat((some_array[0] = '\0', some_array),char, sizeof some_array);
new cchar[];
strmid(char, "bar",0,(( 2)-1));
strdel(char, 2,strlen(char));
strcat((some_array_2[0] = '\0', some_array_2),char, sizeof some_array_2);
}