Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!apple!bloom-beacon!bu-cs!buengc!bph From: bph@buengc.BU.EDU (Blair P. Houghton) Newsgroups: comp.lang.c++ Subject: Re: Isn't sizeof an operator? Message-ID: <2430@buengc.BU.EDU> Date: 30 Mar 89 18:03:21 GMT References: <8903281246.AA26233@wheat-chex.ai.mit.edu> Reply-To: bph@buengc.bu.edu (Blair P. Houghton) Followup-To: comp.lang.c++ Organization: Boston Univ. Col. of Eng. Lines: 32 In article <8903281246.AA26233@wheat-chex.ai.mit.edu> hearn@claris.com writes: >In article <8903202240.AA24954@yahi> tiemann@lurch.stanford.edu writes: >>[...And I wrote...but someone lopped off the attribution...] >>>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. >> >> It also takes a TYPE as an argument instead of an EXPRESSION. > >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. Hurh? If it's resolved at compile time, how can it be an operator that returns the value of a varying quantity? Oh. I get it. I mean "it's not a FUNCTION, it's a compiler-directing operator..." Sorry. I zegged when I shoulda zogged. Not enuff wheat-chex for breakfast. [...discussion of non-overloadability of sizeof deleted...] >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. :-) --Blair "Deja vu."