Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!cdss!culliton From: culliton@cdss.UUCP (Tom Culliton) Newsgroups: comp.lang.c++ Subject: Re: sizeof as a macro (was: references to dereferenced null pointers) Summary: OK so you can't quite do it... Message-ID: <60@cdss.UUCP> Date: 9 Apr 90 17:45:43 GMT References: <5764@videovax.tv.tek.com> <15126@cbnews.ATT.COM> <1448@tkou02.enet.dec.com> Organization: ARINC Research Corp., CDSS Group, Annapolis, MD Lines: 29 In article <58@cdss.UUCP> I wrote.... > Another thought that stems from this and a little puzzle :-) how would you > implement sizeof as a macro? And In article <1448@tkou02.enet.dec.com>, diamond@tkou02.enet.dec.com (diamond@tkovoa) replied: > I don't think you can. How can a macro compute sizeof(-3) without using the > builtin sizeof? (And in case you manage that, here are two more for you: > sizeof -3 (no parentheses needed with an expression), and sizeof(int).) Which is of course absolutely correct. Since I don't generally use sizeof like that it just didn't occur to me. I think the idea is still intresting though. Let me rephrase it to keep myself out of trouble. (a very difficult business) ;^) Given: #define sizeof(type) ... How would you implement the right hand side? BTW "type" is just that, a legitimate type, like "int", "char [10]", "struct XYZ", "[class] WINDOW", etc. Just to forestall any flames, yes, defining macros over keywords is a VERY BAD idea, I neither do it nor advocate it, and duplicating built in funtionality is just as bad. However, thinking about how such things are or can be done is mind broadening. Tom ***************************************************************************** * uunet!culliton@cdss - Tom Culliton at Arinc Research Corp. Annapolis MD * * "I haven't lost my mind -- it's backed up on tape somewhere." * *****************************************************************************