By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

sizeof(aStruct) returns fault number

P: n/a
hello everyone, i have my struct
which is declared locally inside a case of a switch statement of a
function...
don't let Q_UINT8 scare you its just an platform independent Qt 3-3-4,
8bits (1 byte) integer type (and for all practical matter i did try to
use char as well instead of Q_UINT8).. the MANUAL_* variables are just
some globals of type unsigned char..
struct manualStruct {
Q_UINT8 mC1St;
Q_UINT8 mC2St;
Q_UINT8 mC3St;
} *manualVar;
manualVar->mC1St=MANUAL_cap1State;
manualVar->mC2St=MANUAL_cap2State;
manualVar->mC3St=MANUAL_cap3State;
int structSize1=sizeof(manualVar);

now my problem is that sizeof() returns 4... ie 4bytes... how is that
possible? should it not be 3? i repeat i even tried that with chars..
the problem remained...
thank you in advance for your help
nass

Sep 22 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
nass wrote:
hello everyone, i have my struct
which is declared locally inside a case of a switch statement of a
function...
don't let Q_UINT8 scare you its just an platform independent Qt 3-3-4,
8bits (1 byte) integer type (and for all practical matter i did try
to use char as well instead of Q_UINT8).. the MANUAL_* variables are
just some globals of type unsigned char..
struct manualStruct {
Q_UINT8 mC1St;
Q_UINT8 mC2St;
Q_UINT8 mC3St;
} *manualVar;
manualVar->mC1St=MANUAL_cap1State;
manualVar->mC2St=MANUAL_cap2State;
manualVar->mC3St=MANUAL_cap3State;
int structSize1=sizeof(manualVar);

now my problem is that sizeof() returns 4... ie 4bytes... how is that
possible? should it not be 3? i repeat i even tried that with chars..
the problem remained...
It's a POINTER! What's sizeof(void*) on your system?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 22 '06 #2

P: n/a
Victor Bazarov wrote:
nass wrote:
>>
struct manualStruct {
Q_UINT8 mC1St;
Q_UINT8 mC2St;
Q_UINT8 mC3St;
} *manualVar;
manualVar->mC1St=MANUAL_cap1State;
manualVar->mC2St=MANUAL_cap2State;
manualVar->mC3St=MANUAL_cap3State;
int structSize1=sizeof(manualVar);

now my problem is that sizeof() returns 4... ie 4bytes... how is that
possible? should it not be 3? i repeat i even tried that with chars..
the problem remained...

It's a POINTER! What's sizeof(void*) on your system?
And even if you did sizeof(manualStruct), the compiler is free to insert
any padding it chooses.

Sep 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.