----- Original Message ----- From: "Gerhard Fiedler" To: "Microcontroller discussion list - Public." Sent: Tuesday, June 02, 2009 2:21 PM Subject: Re: [PIC] MPLAB SIM PROBLEM - help > Olin Lathrop wrote: > >> Isaac Marino Bavaresco wrote: >>> Many don't know, but "x = 1[p];" is valid and is the same as >>> "x=p[1];". >> >> I find that hard to believe. What data type would 1[p] have? How >> would it know the size of each element? Can you show complete >> example code that actually compiles using this construct? > > Both arrays need a declaration that defines their member type. > > 1[p] could point to (1 + p * sizeof(memberType)). (Not sure this is > legal, but it could be -- given an implicit conversion from int to an > array address.) > > p[1] would point to (p + 1 * sizeof(memberType)). > > If you declare the arrays so that sizeof(memberType)==1, this could > work. > > I don't see any use for this "trick", though... > > Gerhard Not true. As I mentioned before a[b] === b[a] === *(a+b) === *(b+a) This means that as long as one of a and b is a pointer (or array name) and the other an integer type then the syntax is perfectly valid "C". There are no restrictions on the type pointed to. -- Bob Ammerman RAm Systems -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist