sizeof a struct

Given that I'm trying to acquire the information of the size of this struct:

Code:

struct Point2D {int x,y;};

Logically thinking, it should be the size of 2 ints. However, when I checked in the debugger, it gives me a value of 0 when checking its size using sizeof(). Is this normal, or is there something wrong with how I used the struct to get a sizeof = 0?

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

I checked with a debugger again by assigning its value to a variable. That variable isn't 0. But when I checked "sizeof(Point2D)" in the debugger, it gives me a value of 0. My confusion is with what the debugger is doing.

Maybe the problem is that the debugger is (or you are, when using the debugger) a little confused by the fact that sizeof is a compile time operator rather than a function.

Originally Posted by Bjarne Stroustrup (2000-10-14)

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

Post the smallest and simplest compilable program that demonstrates this problem. It might also be a good idea to post about which debugger you used and how you went about using it.

Originally Posted by Bjarne Stroustrup (2000-10-14)

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

I just typed in sizeof(whatever) in the watch window. Not sure how posting a simple compilable program would help.

I have a feeling that this might be the problem: it just does not make sense to me to try and run the debugger when you do not have a compilable program to run. Presumably sizeof(int) works because that is hard coded into the debugger.

Originally Posted by Bjarne Stroustrup (2000-10-14)

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.