Path: utzoo!telly!attcan!uunet!tut.cis.ohio-state.edu!bloom-beacon!apple!claris!hearn From: hearn@claris.com (Bob Hearn) Newsgroups: gnu.g++ Subject: Re: Isn't sizeof an operator? Message-ID: <9120@claris.com> Date: 21 Mar 89 00:14:08 GMT References: <2352@buengc.BU.EDU> <8903202240.AA24954@yahi> Reply-To: hearn@claris.com (Bob Hearn) Distribution: gnu Organization: Claris Corporation, Mountain View CA Lines: 36 In article <8903202240.AA24954@yahi> tiemann@lurch.stanford.edu writes: > > In article <123@riunite.ACA.MCC.COM> rfg@riunite.UUCP (Ron Guilmette) writes: > ["why isn't sizeof declarable as an operator?"] > > Because it's a compiler directive, not a C-language operator. The > result of sizeof (something) is an integer _constant_. If you try to > take the size of something that has a varying size, you will get only > the size of that thing at compile time. > > If you're creating varying-sized data elements, you should keep track of > their sizes yourself. > > --Blair > "But I don't know why you would..." > >It also takes a TYPE as an argument instead of an EXPRESSION. > >Michael You are 100% incorrect. Remember that the topic of discussion here is C++, not C! sizeof is certainly an operator. And it can take a type or an expression as an argument. See Stroustrup, pp. 257-258. It is, however, resolved at compile time. Presumably, it can't be overloaded for this very reason; it is syntactically an operator, but it is not treated the same as other operators. It may be overloadable in the future; C++ is still an evolving language, and recently -> was added to the list of overloadable operators. However, it would be much nicer if it used the dynamic rather than static information where appropriate, like class/structure element dereferencing!! Are you listening, Bjarne??? Unfortunately, for now, there seems to be no alternative but to keep track of the sizes yourself. Not very helpful, I know, but at least correct. :-) Bob Hearn hearn@claris.com