Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!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: <8903281245.AA26230@wheat-chex.ai.mit.edu> Date: 28 Mar 89 12:45:56 GMT Sender: daemon@eddie.MIT.EDU Reply-To: hearn@claris.com Lines: 56 Return-Path: Date: Thu, 23 Mar 89 19:56:57 EST From: MAILER-DAEMON@eddie.mit.edu (Mail Delivery Subsystem) Subject: Returned mail: unknown mailer error 1 To: ----- Transcript of session follows ----- inews: Cannot get user's name 554 "|/usr/local/lib/news/nrecnews -n comp.emacs -x mirror"... unknown mailer error 1 ----- Unsent message follows ----- Received: by EDDIE.MIT.EDU with sendmail-5.45/4.7 id ; Thu, 23 Mar 89 19:56:57 EST Received: from wheat-chex.ai.mit.edu by life.ai.mit.edu; Thu, 23 Mar 89 19:57:31 EST Received: from localhost by wheat-chex.ai.mit.edu; Thu, 23 Mar 89 19:57:29 EST Date: Thu, 23 Mar 89 19:57:29 EST From: gnulists@wheaties.ai.mit.edu Message-Id: <8903240057.AA15865@wheat-chex.ai.mit.edu> To: post-net-emacs@eddie.mit.edu Subject: Re: Isn't sizeof an operator? 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