Re: [Tinycc-devel] Strange sizeof construct

2007-11-23 Thread Fred Weigel
Yes, [] can be applied to any pointer. But, it is an operator, like "+". So, a[i], is an operation involving a and i. In fact, it IS the operation +. a[i] is *(a + i) Now *(a + i) is the same as *(i + a). And thus, a[i] is the same as i[a]. Now, a is the same as a pointer, so we can write i[p]. A

Re: [Tinycc-devel] Strange sizeof construct

2007-11-22 Thread Mike
Right. You said "[] can be applied to any pointer." That sounds right. What's this a few emails ago with [] being applied to immediate values in C99, like this 6[4] Fred Weigel wrote: Marc sizeof is an operator arr evaluates to the base of the array. [] is an operator. since arr is the

Re: [Tinycc-devel] Strange sizeof construct

2007-11-21 Thread Fred Weigel
Marc sizeof is an operator arr evaluates to the base of the array. [] is an operator. since arr is the base of the array, (arr) is the same value (putting in the parentheses doesn't change a thing). The precedence is identical! so, if "sizeof arr[0]" works, then "sizeof (arr) [0]" should be ide

Re: [Tinycc-devel] Strange sizeof construct

2007-11-19 Thread Jens Harms
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 > > > > int main(){ > > int arr[10]; > > printf("%d\n",sizeof arr[0]); // ok > > printf("%d\

Re: [Tinycc-devel] Strange sizeof construct

2007-11-14 Thread Chris Lattner
On Nov 14, 2007, at 5:39 PM, Mike wrote: "(arr)[0]" would be valid yes. But "40[0]" should be invalid, right? Yes, and it is. "40[arr]" is valid of course. -Chris ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org http://lists.nongnu.org/mai

Re: [Tinycc-devel] Strange sizeof construct

2007-11-14 Thread Mike
"(arr)[0]" would be valid yes. But "40[0]" should be invalid, right? Chris Lattner wrote: On Nov 14, 2007, at 5:18 PM, Mike wrote: >>> printf("%d\n",sizeof(arr)[0]); // ok, but why? Why should that be valid syntax? Is C99 really weird or what? (its a immediate value being used in place of a

Re: [Tinycc-devel] Strange sizeof construct

2007-11-14 Thread Chris Lattner
On Nov 14, 2007, at 5:18 PM, Mike wrote: >>> printf("%d\n",sizeof(arr)[0]); // ok, but why? Why should that be valid syntax? Is C99 really weird or what? (its a immediate value being used in place of a pointer.) The C99 grammar says that sizeof is: unary-expression: sizeof unary-expressio

Re: [Tinycc-devel] Strange sizeof construct

2007-11-14 Thread Mike
>>> printf("%d\n",sizeof(arr)[0]); // ok, but why? Why should that be valid syntax? Is C99 really weird or what? (its a immediate value being used in place of a pointer.) -Mike Marc Andre Tanner wrote: On Wed, Nov 14, 2007 at 12:39:18AM +0100, grischka wrote: Could a C guru out there please te

Re: [Tinycc-devel] Strange sizeof construct

2007-11-14 Thread Marc Andre Tanner
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 > > > > int main(){ > > int arr[10]; > > printf("%d\n",sizeof arr[0]); // ok > > printf("%d\n"

Re: [Tinycc-devel] Strange sizeof construct

2007-11-13 Thread Chris Lattner
On Nov 13, 2007, at 3:39 PM, 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 int main(){ int arr[10]; printf("%d\n",sizeof arr[0]); // ok printf("%d\n",sizeof(arr[0])); // ok printf("%d\n",sizeof(a

Re: [Tinycc-devel] Strange sizeof construct

2007-11-13 Thread grischka
> Could a C guru out there please tell me why the following works? > Extra points if you can explain why it makes sense. > > #include > > 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? > r

Re: [Tinycc-devel] Strange sizeof construct

2007-11-13 Thread Simon 'corecode' Schubert
Marc Andre Tanner 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 > > int main(){ > int arr[10]; > printf("%d\n",sizeof arr[0]); // ok > printf("%d\n",sizeof(arr[0])); // ok > pr

[Tinycc-devel] Strange sizeof construct

2007-11-13 Thread Marc Andre Tanner
Hi, Could a C guru out there please tell me why the following works? Extra points if you can explain why it makes sense. #include 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]); //