#define in a struct?

Heya!

I'm using Dev-C 4.9.9.2 and I got into a damn problem, it's probely very easy to solve but I'm too retarded to find a solution :)

This is a small bit of my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
#define base_adress 0x53E50000

struct item_ammount {
     unsigned int fairybow       [0x11A81C];
     unsigned int bomb           [0x11A81D];
     unsigned int bombchu        [0x11A81E];
     unsigned int dekunut        [0x11A81F];
     unsigned int dekustick      [0x11A821];
     unsigned int fairyslingshot [0x11A827];
     unsigned int magicbeans     [0x11A829];
} ammount;

WriteProcessMemory(hProcess, (LPVOID)(base_adress + ammount.bomb), &newdata, 1, NULL);


#define works good with the base_adress but when I used unsigned int for the offset it fucks up the values, so I thought I could just change all the unsigned int's to #define like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
#define base_adress 0x53E50000

struct item_ammount {
     #define fairybow       0x11A81C
     #define bomb           0x11A81D
     #define bombchu        0x11A81E
     #define dekunut        0x11A81F
     #define dekustick      0x11A821
     #define fairyslingshot 0x11A827
     #define magicbeans     0x11A829
} ammount;

WriteProcessMemory(hProcess, (LPVOID)(base_adress + ammount.bomb), &newdata, 1, NULL);


But when I compile it I get this error:

expected primary-expression before ')' token
unqualified-id before numeric constant


The compiler suddenly hates "ammount.bomb" and I can't get this to work. Please help me and mabye explain why this is happening! :=)
I don't think you are doing what you're trying to do.

1
2
3
4
5
struct item_ammount {
     unsigned int fairybow       [0x11A81C];
     unsigned int bomb           [0x11A81D];
//...
} ammount;


This code is making MASSIVE arrays. IE: bomb is an array with 0x11A81D elements.

(LPVOID)(base_adress + ammount.bomb),

Then here, you're adding a pointer to that array (ie: some completely arbitrary value) to base_address, which is probably not what you want to do.


The #define approach doesn't work because #defines are just copy/pasted by the compiler. So when you do this:

1
2
3
4
5
6
7
8
struct item_ammount {
     #define fairybow       0x11A81C
     #define bomb           0x11A81D
//...
} ammount;

//...
(LPVOID)(base_adress + ammount.bomb),


The compiler replaces ammount.bomb with ammount.0x11A81D which is nonsense.


It seems to me like you want to add a literal value of 0x11A81D. In which case you would want a constant variable (not an array):

1
2
3
4
struct item_ammount
{
  static const unsigned bomb = 0x11A81D;
} ammount;


Although putting those constants in a struct is a little silly.

Also you're spelling 'amount' wrong.
Thanks alot for the answer and for explaining how it works. I guess this happens when a guy acts before thinking :).

I can agree that having those constants in a struct is abit silly yes, but it feels nice to write amount.bomb instead of bombamount, but mabye theres another way to do that, I dunno.

And thanks for respelling ammount, I always thought it was something strange with that word!
Topic archived. No new replies allowed.