Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 135,943 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,744 people online right now. Registration is fast and FREE... Join Now!




struct size check at compile-time

 
Reply to this topicStart new topic

struct size check at compile-time, need to verify a struct's size before the code is executed

roubi
19 May, 2008 - 11:39 PM
Post #1

New D.I.C Head
*

Joined: 19 May, 2008
Posts: 1

I know that the following does not compile !

#if sizeof(myStruct) != 9
#error "myStruct: wrong dimension"
#endif

Is there an alternative to check a struct's size at compile-time ??
User is offlineProfile CardPM
+Quote Post

Cerolobo
RE: Struct Size Check At Compile-time
19 May, 2008 - 11:51 PM
Post #2

D.I.C Regular
Group Icon

Joined: 5 Apr, 2008
Posts: 440



Thanked: 31 times
My Contributions
Well, you can manually calculate the number of bytes required.

Why would you actually want to do something like

#if sizeof(myStruct) != 9
#error "myStruct: wrong dimension"
#endif

It throws all notions of portability out the window...
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 08:44AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month