Thursday, July 30, 2009

How do we find the size of any object ( builtin or userdefined) without using sizeof operator ? C++?

This is some what tricky.


The only condition is that do not use sizeof operator and find the size of an object..





Possible???

How do we find the size of any object ( builtin or userdefined) without using sizeof operator ? C++?
Is it a riddle?


sizeof is a 'trick' of the compiler and does not give you the size of an object, but the size of the declared object.





Being a compile time operation I could simply read the object source(s) and use the known value as size.





I know char size is 1 and MyObject ... has lenght 6 because has 2 char and a pointer ecc...





But why should I do this? I can't understand.


No comments:

Post a Comment