Path: utzoo!attcan!uunet!mcvax!cernvax!ethz!visinfo From: visinfo@ethz.UUCP (VISINFO Moderators) Newsgroups: comp.lang.c Subject: Re: Is this portable? Keywords: c,comp.std.c,comp.lang.c,portability Message-ID: <870@ethz.UUCP> Date: 12 May 89 13:02:10 GMT References: <1914@plx.UUCP> Reply-To: visinfo@bernina.UUCP (VISINFO Moderators) Organization: ETH Zuerich, Switzerland Lines: 37 In Article 15145 of comp.lang.c Evan writes >This works on my machine, but I am curious as to whether it is "officially" >correct and portable C. I can think of some machines where it could be >trouble > > main() > { int array[10], *ptr, j; > > for(j=0; j<10; j++) > array[j]=j; > > ptr= &(array[1]); > > for(j= -1; j<9; j++) > printf("%d\n", ptr[j]); > } I suppose this to be (rather) portable, 'cause the compiler takes the adress of 'ptr', adds j*sizeof(int) and writes out the content of the memory location this pointer is pointing to. So when K&R says : pointer+int is OK : , let us use it. Just imagine the following source (travelling in a string): { char c[]= "abc"; char *runner; runner=&(c[2]); while (runner!=c) runner--; } I see no dangers in it (it's just another way to confuse any kind of range- checking facility) ! Tony