Weird behavior of #if, invalid instruction
#1

So, I have this example script:
pawn Code:
#include <a_samp>

#if !defined GetVehicleColor
new vehiclecolor[MAX_VEHICLES*2 char];
stock GetVehicleColor(vehicleid, &color1, &color2)
{
    color1 = vehiclecolor{vehicleid};
    color2 = vehiclecolor{vehicleid+1};
}
stock SaveVehicleColor(vehicleid, color1, color2)
{
    vehiclecolor{vehicleid} = color1;
    vehiclecolor{vehicleid+1} = color2;
}
#else
stock SaveVehicleColor(vehicleid, color1, color2)
{
    #pragma unused vehicleid, color1, color2
}
#endif

main()
{
    new c1,c2;
    print("Start");
    GetVehicleColor(0, c1, c2);
    printf("%d %d", c1, c2);
}
It's supposed to check if a default GetVehicleColor is supplied (like from YSF), and if not, add its own implementation (which needs external color saving). To me, this code seems perfectly valid. So why the hell is this shown in the console when I run the script (crashdetect):
Code:
Start
[debug] Run time error 6: "Invalid instruction"
[debug]  Unknown opcode 0x0 at address 0x00000928
[debug] AMX backtrace:
[debug] #0 00000928 in main () from <unknown>
Script[gamemodes/../test.amx]: Run time error 6: "Invalid instruction"
Number of vehicle models: 0
Some things to note:
  • The #include is needed only for print and printf, not for GetVehicleColor.
  • When I access "vehiclecolor" in "main", is says 'undefined symbol "vehiclecolor"'.
  • If I put #error DEFINED under #if, it correctly outputs the error.
  • If I put #error NOTDEFINED under #else, it also outputs the error.
  • If I add "hello[]" in the parameter list of the second SaveVehicleColor, it outputs "function heading differs from prototype" on that line.
This completely baffles me, is the compiler compiling both blocks, even when there is #else?
Reply


Messages In This Thread
Weird behavior of #if, invalid instruction - by IllidanS4 - 14.05.2015, 21:16
Re: Weird behavior of #if, invalid instruction - by Gammix - 15.05.2015, 05:41
Re: Weird behavior of #if, invalid instruction - by IllidanS4 - 15.05.2015, 14:18
Re: Weird behavior of #if, invalid instruction - by IllidanS4 - 30.05.2015, 10:13

Forum Jump:


Users browsing this thread: 1 Guest(s)