Another silly question

Tim_CDC_Roberts at cup.portal.com Tim_CDC_Roberts at cup.portal.com
Tue May 2 01:55:44 AEST 1989


Ok, folks.  In regards to  "a[i] == *(a+i) == *(i+a) == i[a]", let me
refer to the oft-used example  2["hello"].

I agree that this works and is equivalent to "hello"[2].  I've seen it
in books and postings.  My simple question is why?  (Please don't submit
30 replies saying "because the book says so"...)  Doesn't that equivalence
imply that the pointer type is somehow "stronger" than the simple type?
Is that, in fact, the case?  Is a compiler force to examine all of the
elements in a pointer expression and establish the "master type" of the
expression?  If I mix two pointer types, as in
  char * c;
  long * ell;
     return c + ell;
is this anarchy?  Is it a syntax error?  What is sizeof(*(c+ell))?

Inquiring minds want to know.

Tim_CDC_Roberts at cup.portal.com                | Control Data...
...!sun!portal!cup.portal.com!tim_cdc_roberts |   ...or it will control you.



More information about the Comp.lang.c mailing list