size of a datatype without using sizeof

To my mind, this fits into the category of “how do I add two ints without using ++, += or + ?”. It’s a waste of time. You can try and avoid the monsters of undefined behaviour by doing something like this.

size_t size = (size_t)(1 + ((X*)0));

Note that I don’t declare a variable of type or pointer to X.

Leave a Comment