Re: Technical reason why sizeof() is an operator and not a function?



In article <dqit7c$7ab$1@xxxxxxxxxxxxxxxxxxxx>, kers@xxxxxxxxxx says...
> Gerry Quinn wrote:
>
> > int* ptr = malloc( 100 * sizeof( int ) );
>
> Too vulnerable to changes in the type of `ptr`. Shiver.

That's irrelevant to the question of whether sizeof should take
brackets.

That said, int pointers don't usually change. In C++ the equivalent
is:

int* ptr = new int[ 100 ];

...and that doesn't seem to bother anyone.

- Gerry Quinn
.



Relevant Pages

  • Re: How can I get the size of this?
    ... >>>I am now having a problem at using sizeof() function ... Again I *prefer* return without brackets - unless of course I'm ... evaluating something in which the brackets make it clear that the ... David Webber ...
    (microsoft.public.vc.language)
  • Re: A Certain Size/sizeof
    ... > Truly an ugly array size expression, ... Firstly, sizeof is not a function, therefore 'sizeof BufferTestNumbers' ... invoke that operator and that takes a typename in brackets, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Flexible arrays - v confused
    ... When you are in the habit of omitting the brackets for "sizeof var", ... I use space in 'sizeof ' so that sizeof operator cannot so easily be confused with a function. ...
    (comp.lang.c)
  • Re: sizeof(x) in C and in C++
    ... >> Of course you can't find it, sizeof() is a C operator not a function. ... I'd like to amend that even the brackets are optional. ... > prototype. ...
    (comp.lang.c)