Arrays
#1

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
Reply
#2

What does the console print? 16?
Reply
#3

Lol, just checked this.
It prints:

pawn Код:
52
qwertyqwertyqwertyzxcvbbnmqwertyqwertyqwertyzxcvbbnm
Run time error 6: "Invalid  instruction"
Reply
#4

Well .. I do not know, I have everything well. no problems found
Reply
#5

Yeah I don't really understand your problem here.
Reply
#6

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?
Reply
#7

I have no problem, just wondering why it was the format size of 512 cells with a variable works fine in 16 cells
Reply
#8

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
Reply
#9

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?
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)