Piru wrote:
@Karlos
Nor does it handle sizeof variable.
Of course not. The point was that it is possible to use a macro to evaluate the size of a structure/primitive type, nothing more. Just to demonstrate that (some of) the behaviour of sizeof() could be implemented as a macro, even if the actual sizeof() itself is not.
@Koafter
Agreed, it's disgusting and I'd want to shoot anybody I saw using anything quite like that*.
(*I have used some ugly macros in my time but only to abstract something that simply couldn't be represented more cleanly in the language itself. The above example naturally does not fall into this category).
C is a fantastic language but when you do end up having to depend on macros for things that you could readily do in C++ with inline functions and templates you really do see the point in moving up the language food chain ;-) Other than conditional compilation, I rarely use macros in C++ for anything.
I make no secret of the fact I regard C++ as utterly superior to C. Not because of the OO features per se (which I do like of course) but simply because it provides much cleaner ways of doing things that in C you would otherwise end up using the preprocessor or other contrivances for. It also provides greater error checking and general robustness and last but not least, still allows you to do things low level when you need to.