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

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

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 ...
  • 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, ...
  • 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. ...
  • 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. ...