tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] Strange sizeof construct


From: Jens Harms
Subject: Re: [Tinycc-devel] Strange sizeof construct
Date: Mon, 19 Nov 2007 12:03:12 +0100
User-agent: Thunderbird 2.0.0.6 (X11/20071022)

On Wed, Nov 14, 2007 at 12:39:18AM +0100, grischka wrote:
> > Could a C guru out there please tell me why the following works? > > Extra points if you can explain why it makes sense. > > > > #include <stdio.h> > > > > int main(){
> > int arr[10];
> > printf("%d\n",sizeof arr[0]);  // ok
> > printf("%d\n",sizeof(arr[0])); // ok
> > printf("%d\n",sizeof(arr)[0]); // ok, but why?
> > return 0;
> > }
> > And what about that one: > > printf("%d\n",sizeof (0)[arr]);

Yep even stranger. The good thing is that if you add another pair of
parantheses tcc takes it and life is good.

  printf("%d\n",sizeof((arr)[0]));
  printf("%d\n",sizeof((0)[arr]));


I think your problem is the syntax of a[b] and the sizeof operator.

int a;

sizeof a == sizeof (a) == sizeof (int)
int *v;

v[5] == *(v+5) == *(5+v) == 5[v] last but not least insert parenthesis: 
((v)[(5)])

ok?















reply via email to

[Prev in Thread] Current Thread [Next in Thread]