Please help me figure out what this code is not C! $ 0.50 Paypal pay [paypal address] [address thanks]

Q: I need to know what this line of code does and why. Anyone who knows C, explain what each step does. Thanks a lot!

# define MAKE_COOL_GAMES (z, w) (int) (u0026 (((z *) 0) u003e w))

edit: I will be $ 0.50 (fifty cents) to anyone who gives me a good answer . I will PM your given. Thanks!


Re:Originally posted by: guy
it looks like it's purpose is to calculate the offset of member 'w' in structure 'z'

the ((z*)0) part creates a null pointer to something of type 'z'
the ->w part references member 'w' of this 'z' type thingie
the & then takes the address of this 'w'
normally the address of 'z->w', is address of 'z' + some fixed offset to get member 'w'.
but since the z part is a null pointer, thus having address 0, the result is equivalent to just the offset of 'w'.

Thank you so much! I PMed you about the reward.


Re:Originally posted by: guy
it looks like it's purpose is to calculate the offset of member 'w' in structure 'z'

the ((z*)0) part creates a null pointer to something of type 'z'
the ->w part references member 'w' of this 'z' type thingie
the & then takes the address of this 'w'
normally the address of 'z->w', is address of 'z' + some fixed offset to get member 'w'.
but since the z part is a null pointer, thus having address 0, the result is equivalent to just the offset of 'w'.

Nifty! Makes sense to me. I was stumped by the ((z*)0) part.

So the code

struct mystruct {
int a
int b
};

and I called MAKE_COOL_GAMES(mystruct, b)

I would get (int)(&(((mystruct *)0)->b)) which is the offset address value of b in the context of a struct of the type 'mystruct'?


Re:it looks like it's purpose is to calculate the offset of member 'w' in structure 'z'

the ((z*)0) part creates a null pointer to something of type 'z'
the ->w part references member 'w' of this 'z' type thingie
the & then takes the address of this 'w'
normally the address of 'z->w', is address of 'z' + some fixed offset to get member 'w'.
but since the z part is a null pointer, thus having address 0, the result is equivalent to just the offset of 'w'.


Re:Look at your other post I would reccomend reading up on pointers and memory allocation in C. I cannot get that definition to compile
so I'm not sure if it is syntaticly correct.

Re:Originally posted by: guy
Assuming z and w are integers… I think it is trying to make the memory contents located at z equal to the value of w… and then returning the
memory location… I think

But what does each symbol/character in the code do? I don't understand what "(&(((z *)0)->w))" does. Thanks.


Re:Assuming z and w are integers… I think it is trying to make the memory contents located at z equal to the value of w… and then returning the
memory location… I think

Actually I know that's wrong…


Re:Originally posted by: guy
It's just a preprocessor definition…

Before the code is compiled the preprocessor replaces all instances of MAKE_COOL_GAMES(z, w) in the code
with (int)(&(((z *)0)->w))

I figured out that part, but what does the second part of the code do?

(int)(&(((z *)0)->w))


Re:It's just a preprocessor definition…

Before the code is compiled the preprocessor replaces all instances of MAKE_COOL_GAMES(z, w) in the code
with (int)(&(((z *)0)->w))


Related posts

Leave a comment

0 Comments.

Leave a Reply


click to changeSecurity Code

[ Ctrl + Enter ]