Fancy defines
#1

what is wrong with this code and how to fix it?

Код:
#include <a_samp>

#define ha_%0::%1.%2(%3) (2*%3)
#define lol:%0) ha_%0)

main() {
    printf("%i", onConnect(42));
}

onConnect(lol:lol)
{
//  return (2*6);
    return ha_lol::ha.hi(6); // line 12
}
Код:
input(12) : error 1: expected token: ";", but found "::"
input(12) : error 29: invalid expression, assumed zero
input(12) : error 17: undefined symbol "ha"
input(12) : fatal error 107: too many error messages on one line
Error: The compiler failed. (no error code)
Reply
#2

Run pawncc with -l to find out. Those macros are broken though:
pawn Код:
main() {
    printf("%i", onConnect(42));
}

onConnect(ha_lol)
{

    return ha_lol::ha.hi(6);
}
#e:
Ok, I've found the problem - and it's quite tricky (and I've learned cool things from this).

The code:
pawn Код:
#include <a_samp>

#define ha::%0::%1.%2(%3) (2*%3)
#define lol:%0) ha_%0)

main() {
    printf("%i", onConnect(42));
}

onConnect(lol:lol)
{
    return ha::lol::ha.hi(6); // line 12
}
http://forum.sa-mp.com/showthread.ph...175#post785175 In that tutorial you can find out how macros are built and stuff, but there is one little error - % is a valid character in macro definition, and you need invalid character to start 2 part of macro.
pawn Код:
#define ha_%0) bar_%0
won't work, because _ is legal character. You have to change _ to some illegal char, like : to make it work.

#e2:
My explanation isn't valid, but results are
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)