Arrays -
sent161 - 29.08.2011
Why when using a format not valid limit of an array?
Sorry for my English, unnecessarily I live in Russia and use ******;
PHP код:
new SeNT[16];//Global
public OnGameModeInit()
{
format(SeNT,512,"qwertyqwertyqwertyzxcvbbnmqwertyqwertyqwertyzxcvbbnm");
printf("%d",strlen(SeNT));
print(SeNT);
}
After checking the code, We can see in the console that the value in the format of the size of the array.
I await your replys with respect, Dmitry
Re: Arrays -
Backwardsman97 - 29.08.2011
What does the console print? 16?
Re: Arrays -
PowerPC603 - 29.08.2011
Lol, just checked this.
It prints:
pawn Код:
52
qwertyqwertyqwertyzxcvbbnmqwertyqwertyqwertyzxcvbbnm
Run time error 6: "Invalid instruction"
Re: Arrays -
sent161 - 29.08.2011
Well .. I do not know, I have everything well. no problems found
Re: Arrays -
Backwardsman97 - 30.08.2011
Yeah I don't really understand your problem here.
Re: Arrays -
Pghpunkid - 30.08.2011
I think your getting an error because there is no main(). Open a new file copy the code for main, paste it in and check again.
Why are you trying to cram 512 characters into a 16 character array?
Re: Arrays -
sent161 - 30.08.2011
I have no problem, just wondering why it was the format size of 512 cells with a variable works fine in 16 cells
Re: Arrays -
JaTochNietDan - 30.08.2011
It's because you have specified 512 cells in the format function, so it continues writing to memory even though you don't have any memory allocated, which is a buffer overflow.
http://en.wikipedia.org/wiki/Buffer_overflow
Re: Arrays -
sent161 - 30.08.2011
Sorry, I disagree with you. Because, in the Pascal format has no arguments to the variable in the. ... Below is an example
PHP код:
var
text : string;
begin
// Just 1 data item
ShowMessage(Format('%s', ['Hello']));
// A mix of literal text and a data item
ShowMessage(Format('String = %s', ['Hello']));
ShowMessage('');
// Examples of each of the data types
ShowMessage(Format('Decimal = %d', [-123]));
ShowMessage(Format('Exponent = %e', [12345.678]));
ShowMessage(Format('Fixed = %f', [12345.678]));
ShowMessage(Format('General = %g', [12345.678]));
ShowMessage(Format('Number = %n', [12345.678]));
ShowMessage(Format('Money = %m', [12345.678]));
ShowMessage(Format('Pointer = %p', [addr(text)]));
ShowMessage(Format('String = %s', ['Hello']));
ShowMessage(Format('Unsigned decimal = %u', [123]));
ShowMessage(Format('Hexadecimal = %x', [140]));
end;
If you think about. then we get a variable is needed to define the format for future use ...
Or am I wrong?
Re: Arrays -
Pghpunkid - 31.08.2011
Pascal is not pawn.. so trust JaTochNietDan with what hes saying.
EDIT: After further reviewing your Pascal code, it appears as if Pascal is not looking for a determined length of the string. So Pascal i presume can handle that. Its the same as apstring in C++. But for arrays, in Pawn, you are exceeding the memory of the array, as JaTochNietDan said.