0

Im trying to make a macro for padding my classes which i use in game hacking. Let me show you what i am trying to do:

#define pad(loc, size)  private: \
                    char _pad#loc[#size]; \
                    public:

then i want to use it like:

class C_VTable {
public:
   float member;          // <- public
   pad(0x4, 0x30);        // <- private im not sure how to make the pad name be like pad0x4
   float anothermember;   // <- public again
};

How can i do this, because i get an error saying it expected a ; a little messy, but i hope you understand.

Any help is greatly appreciated :)

Ranarrr
  • 15
  • 8

1 Answers1

4

Use the ## paste operator to combine two tokens together. Also, don't stringify the size using # - you don't want a string inside the square brackets.

#define pad(loc, size)  private: \
                    char __pad##loc[size]; \
                    public:
aschepler
  • 70,891
  • 9
  • 107
  • 161
  • Thank you very much. Another question, if i do pad( 0x7AE, 2 ) is the pad name going to be __pad0x7AE[2], __pad7AE[2] or __pad1966[2] (7AEh)? – Ranarrr Aug 17 '16 at 18:30
  • The field name will be `__pad0x7AE`. The token gets pasted raw just as you spelled it. – aschepler Aug 17 '16 at 18:33