Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!rochester!pt.cs.cmu.edu!g.cs.cmu.edu!ckk From: ckk@g.cs.cmu.edu (Chris Koenigsberg) Newsgroups: net.lang.c Subject: Example Program: a[i]=b[i++] non-portability Message-ID: <359@g.cs.cmu.edu> Date: Mon, 7-Apr-86 17:32:31 EST Article-I.D.: g.359 Posted: Mon Apr 7 17:32:31 1986 Date-Received: Thu, 10-Apr-86 00:44:58 EST Organization: Carnegie-Mellon University, CS/RI Lines: 40 I mentioned (article title "*p++ = *p and more") that the PCC's on the Sun2 and the IBM RT PC treated "a[i]=b[i++]" differently, and some people said I must have been mistaken. I dug up an example program which displays the non-portability by printing different results on the two machines. Try this on yours and see what you get! Here is a short program displaying the problem: ************* /* testing certain implementation-dependent features of compilers. */ #include main(argc, argv) {char a[10];static char b[]="abcdefghij";int i,j; printf("a =%s, b=%s\n", a, b); printf("Looping over i..."); while(b[i] != 0) a[i] = b[i++]; printf("New a ="); for(i=0;i<=10;printf("%c",a[i++]));printf(", b=%s\n",b); fflush(stdout); } ************** On a sun, the output looks like: a =, b=abcdefghij Looping over i...New a =abcdefghij^@, b=abcdefghij ************** And on the IBM RT PC, the output looks like: a =, b=abcdefghij Looping over i...New a =^@abcdefghij, b=abcdefghij ************** Note: The "^@" was actually a null character, in the output. On the sun, a[0] gets b[0], but on the RT PC, a[1] gets b[0] and a[0] is a null. Chris Koenigsberg ckk@g.cs.cmu.edu , or ckk%andrew@pt.cs.cmu.edu {harvard,seismo,topaz,ucbvax}!g.cs.cmu.edu!ckk (412)268-8526 Center for Design of Educational Computing Carnegie-Mellon U. Pgh, Pa. 15213