Click here to Skip to main content
15,922,007 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to find out the size of a structure without using sizeof Pin
Rajasegar11-Jul-07 3:22
Rajasegar11-Jul-07 3:22 
QuestionRe: How to find out the size of a structure without using sizeof Pin
David Crow11-Jul-07 3:31
David Crow11-Jul-07 3:31 
AnswerRe: How to find out the size of a structure without using sizeof Pin
CPallini11-Jul-07 3:26
mveCPallini11-Jul-07 3:26 
QuestionRe: How to find out the size of a structure without using sizeof Pin
David Crow11-Jul-07 3:28
David Crow11-Jul-07 3:28 
AnswerRe: How to find out the size of a structure without using sizeof Pin
CPallini11-Jul-07 3:32
mveCPallini11-Jul-07 3:32 
GeneralRe: How to find out the size of a structure without using sizeof Pin
Emmanouil11-Jul-07 3:47
Emmanouil11-Jul-07 3:47 
GeneralRe: How to find out the size of a structure without using sizeof Pin
David Crow11-Jul-07 4:02
David Crow11-Jul-07 4:02 
AnswerRe: How to find out the size of a structure without using sizeof Pin
Bram van Kampen11-Jul-07 15:16
Bram van Kampen11-Jul-07 15:16 
There is some crap being posted here.
The only time this is an issue is when you receive a pointer to a structure. If you receive a structure, the Compiler will know the size from the declaration. The Windows Standard way of dealing with pointers to structures of variable size is by using a member c_Bytes as the first member of a structure. This member must be guaranteed to always be initialised to the size of the structure. However, this is only the top of the iceberg, the problem is far larger, particularly if you deal with data structures generated by different compilers. For starters there is the Packing Method. The Structure {char Name[5],PhoneNumber[7]}; would by default be compiled into an object of 16 (NOT 12) bytes. An extra 3 bytes would be placed after Name to make PhoneNumber start at a DWORD boundary, and an extra byte would then be added to the entire structure, so that an array of it would have each element on a DWORD boundary.

You can control this behaviour with a #pragma pack in the header file that declares the structure. (packing for a structure is set at Declaration level, NOT at Useage level). #pragma pack(1) would indeed create a 12 byte structure.

Another issue is when you use structures generated by different compilers are dependent on issues of the kind of 'Howmany bytes does an int occupy'. You can circumvent a lot of this by using WORD and DWORD types, which most( but not All) compiler writers agree occupy 2 resp 4 bytes. Do not forget, an int under WIN16 was 2 Bytes, under WIN32 it is 4. So, the same Structure Declaration will lead to entrely different Sizes and Offsets under WIN16 compared to WIN32.
Returning to your original question: Is there a (generic)way of determining the Size of a Structure without using the sizeof operator, the answer is No, Definitely Not. sizeof is not a function, it is a reserved name which the compiler at compile time resolves to the size of the object by reference to the symbol table. If the size is not known at compile time, the compiler provides NO alternative mechanism, you must create your own runtime mechanism to transmit the size of the object a pointer points to inside the object.

LateNightsInNewry

GeneralRe: How to find out the size of a structure without using sizeof Pin
DevMentor.org11-Jul-07 19:11
DevMentor.org11-Jul-07 19:11 
QuestionHelp: Media seek in directshow Pin
liur1711-Jul-07 2:34
liur1711-Jul-07 2:34 
AnswerRe: Help: Media seek in directshow Pin
Mark Salsbery11-Jul-07 9:13
Mark Salsbery11-Jul-07 9:13 
GeneralRe: Help: Media seek in directshow Pin
liur1711-Jul-07 14:29
liur1711-Jul-07 14:29 
Questionfatal error C1083: Cannot open include file: 'dshow.h': No such file or directory Pin
yaminisridaran11-Jul-07 1:12
yaminisridaran11-Jul-07 1:12 
AnswerRe: fatal error C1083: Cannot open include file: 'dshow.h': No such file or directory Pin
Sam_c11-Jul-07 2:10
Sam_c11-Jul-07 2:10 
GeneralRe: fatal error C1083: Cannot open include file: 'dshow.h': No such file or directory Pin
yaminisridaran11-Jul-07 2:18
yaminisridaran11-Jul-07 2:18 
GeneralRe: fatal error C1083: Cannot open include file: 'dshow.h': No such file or directory Pin
Sam_c11-Jul-07 2:39
Sam_c11-Jul-07 2:39 
GeneralRe: fatal error C1083: Cannot open include file: 'dshow.h': No such file or directory Pin
liur1711-Jul-07 2:41
liur1711-Jul-07 2:41 
AnswerRe: fatal error C1083: Cannot open include file: 'dshow.h': No such file or directory Pin
kdehairy11-Jul-07 2:51
kdehairy11-Jul-07 2:51 
QuestionRe: fatal error C1083: Cannot open include file: 'dshow.h': No such file or directory Pin
David Crow11-Jul-07 3:14
David Crow11-Jul-07 3:14 
AnswerRe: fatal error C1083: Cannot open include file: 'dshow.h': No such file or directory Pin
yaminisridaran11-Jul-07 18:35
yaminisridaran11-Jul-07 18:35 
AnswerRe: fatal error C1083: Cannot open include file: 'dshow.h': No such file or directory Pin
yaminisridaran11-Jul-07 18:39
yaminisridaran11-Jul-07 18:39 
GeneralRe: fatal error C1083: Cannot open include file: 'dshow.h': No such file or directory Pin
Hamid_RT11-Jul-07 19:35
Hamid_RT11-Jul-07 19:35 
AnswerRe: fatal error C1083: Cannot open include file: 'dshow.h': No such file or directory Pin
Mark Salsbery11-Jul-07 9:18
Mark Salsbery11-Jul-07 9:18 
GeneralRe: fatal error C1083: Cannot open include file: 'dshow.h': No such file or directory Pin
yaminisridaran11-Jul-07 18:30
yaminisridaran11-Jul-07 18:30 
QuestionStoring a Refrence in a Tag Pin
InOut.NET11-Jul-07 0:23
InOut.NET11-Jul-07 0:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.