sizeof(aStruct) returns fault number

N

nass

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
 
V

Victor Bazarov

nass said:
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
 
R

red floyd

Victor said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top