Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!mit-eddie!WHEATIES.AI.MIT.EDU!gnulists From: gnulists@WHEATIES.AI.MIT.EDU Newsgroups: comp.lang.c++ Subject: Re: Isn't sizeof an operator? Message-ID: <8903281246.AA26233@wheat-chex.ai.mit.edu> Date: 28 Mar 89 12:46:28 GMT Sender: daemon@eddie.MIT.EDU Reply-To: hearn@claris.com 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