Re: sizeof(array) with variable-length array parameter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 09, 2008 at 04:51:14PM +0100, Andrew Haley wrote:
> 
> Well, OK, you may either do
> 
> int foo(int n, int p[])
> 
> or
> 
> int foo(int n, int p[])

int bar(int n, int p[n]) I presume...

  I am perfectly OK with sizeof returning sizeof(int*) for your
foo() function, but it just feels so wrong to do it when the size
is so easily accessible...

> 
> but sizeof doesn't distinguish these two cases.  In any case, how would
> you do it?  Would an assignment to n change the result of sizeof, or not?
> If not, you'd have to create a "shadow" variable.


  Sure not, it is not changed when you do (on a 32-bit platform):

int foo()
{ int s=10,a[s];
  s=11;
  assert(sizeof s==40);
}

  Try it... Why should the behaviour be so much different in the
parameter passing case?

> 
> But that would break compliant code.  Why would you want to do that?

  OK, that's the only argument I buy. 

Pjotr

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux