SA-MP Forums Archive
Confusion: PAWN doesn't differentiate between i and d specifiers? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Discussion (https://sampforum.blast.hk/forumdisplay.php?fid=84)
+---- Thread: Confusion: PAWN doesn't differentiate between i and d specifiers? (/showthread.php?tid=573624)



Confusion: PAWN doesn't differentiate between i and d specifiers? - [KHK]Khalid - 09.05.2015

Having used C languages before, I already realize that there's a difference between - the two specifiers - i and d when it comes to output and input. I had never bothered to test it out in PAWN though, but by chance it popped in my head lately and this is when the weird results came up...

Test code:
pawn Code:
// output test...
printf("printf(output) '051' with d specifier: %d", 051);
printf("printf(output) '051' with i specifier: %i", 051);
// input test...
new integer;
// first
sscanf("051", "d", integer);
if(integer == 51) // still octal
    print("sscanf(input) '051' with d specifier: 51");
else if(integer == 41) // 41 the decimal of 051
    print("sscanf(input) '051' with d specifier: 41");
// second
sscanf("051", "i", integer);
if(integer == 51) // still octal
    print("sscanf(input) '051' with i specifier: 51");
else if(integer == 41) // 41 the decimal of 051
    print("sscanf(input) '051' with i specifier: 41");
Result:
Code:
printf(output) '051' with d specifier: 51
printf(output) '051' with i specifier: 51
sscanf(input) '051' with d specifier: 51
sscanf(input) '051' with i specifier: 51
Is it my test code? Am I doing it wrong? If so, then can you drop good code that would give out correct/expected results?


Re: Confusion: PAWN doesn't differentiate between i and d specifiers? - maddinat0r - 09.05.2015

Your code is not wrong. In PAWN generally (this is not a PAWN feature though, "sscanf" is a 3rd-party plugin/function and "format" was made by Kalcor), 'd' and 'i' are treated as the same (optionally signed decimal integer).
AFAIK "format" (and thus "printf") doesn't support octal values at all (though it supports hexdecimal values through the 'x' and 'h' specifier).
"sscanf" on the other hand supports octal values through the 'o' specifier.