Possible Duplicate:
Is it possible to print out the size of a C++ class at compile-time?
Can I output the size of an object at compile time? Since the compiler already has this information when it is compiling a source file, can I see it (at compile time) rather than going through the lengthy process of outputting the size somewhere in my application’s console or the debug output window?
This will be very useful especially when I am able to compile single source files which saves me tremendous amounts of time when working on large projects.
Yes. The possible duplicate prints the size as error message, which means the compilation will not succeed.
However, my solution prints the size as warning message, which means, it will print the size, and the compilation will continue.
Warning message:
Demo : http://www.ideone.com/m9eg3
Note : the value of N in the warning message is the value of sizeof(int)
The above code is improved one, and my first attempt was this:
Warning message:
Demo : http://www.ideone.com/mhXjU
The idea is taken from my previous answer to this question: