nevermind

Adrian Tung

Golden Member
Oct 10, 1999
1,370
1
0
Where did you dig this up from?

My interpretation:

It looks as if the define is trying to cast a NULL value (i.e. the value 0) to a pointer of type z to access its member variable w. This would certainly cause an Access Violation fault no matter what z and w is....


:)atwl
 

bsobel

Moderator Emeritus<br>Elite Member
Dec 9, 2001
13,346
0
0
First; Ok, fess up time, whats going on here? Is this someones extra credit on their homework? This EXACT question was asked in this thread earlier today (and that poster also cross posted here in OT).

Second; There is a forum called 'applications, PROGRAMMING, and games'. OffTopic is not for programming questions.

Third; Fess up, the chance that both of you randomly asked the same question about the same obscure technique to get the integer offset of a structure member approaches zero quite quickly.

Bill
 

bsobel

Moderator Emeritus<br>Elite Member
Dec 9, 2001
13,346
0
0
It looks as if the define is trying to cast a NULL value (i.e. the value 0) to a pointer of type z to access its member variable w. This would certainly cause an Access Violation fault no matter what z and w is....

Actually it wouldn't, it returns the count (in bytes) to the structure element. It never attempts a write or even a read at that location.

Bill
 

bsobel

Moderator Emeritus<br>Elite Member
Dec 9, 2001
13,346
0
0
Originally posted by: Cheese78CA
Question answered. Thanks for all the help.

Answer my question, was this for your homework or what?
Bill
 

Cheese78CA

Senior member
Jul 6, 2000
344
0
0
To tell you the truth, no. I've graduated and am not currently doing any kind of C/C++ work.

Originally posted by: bsobel

Answer my question, was this for your homework or what?
Bill

 

bsobel

Moderator Emeritus<br>Elite Member
Dec 9, 2001
13,346
0
0
To tell you the truth, no. I've graduated and am not currently doing any kind of C/C++ work.

Then come on and share, why the same weird question from two users on the same day? I can't believe that was a coincidence... The only thing changed in the two threads was the macro name.

Bill
 

Adrian Tung

Golden Member
Oct 10, 1999
1,370
1
0
Actually, being a C/C++ programmer, I'd like to understand the logic behind that macro. I couldn't find it anywhere, so if my memory serves me correct, it looks like:

#define TEST(z, w) int(&(((z*)0)->w))

So...... how does it work? My primitive mind :)D) immediately drew my attention to the ((z*)0)->w part, which gave me my original conclusion.


:)atwl