Question about VMS C

steve emmerson steve at umigw.MIAMI.EDU
Tue Aug 30 23:30:57 AEST 1988


In article <32725 at cca.CCA.COM> g-rh at CCA.CCA.COM (Richard Harter) writes:
>
>char p[256];
>foo () {
>  int i,j, *s[128];
>  for (i=0;i<128;i++) s[i] = (int *)malloc(128*sizeof(int));
>  for (i=0;i<128;i++) {
>    p[i] = ' ';
>    p[i+128] = ' ';
>    for (j=0;j<128;j++) s[i][j] = 0;
>    }
>  }
>
>When this code was executed sundry things were zeroed outside of s and
>the vectors pointed to by the elements of s.  When the double subscripting
>was changed to *(s[i]+j) = 0 the code executed correctly.  The double
>subscripting executes correctly on a host of UNIX machines and on PRIMOS.

I ran accross the same problem apparently.  Here's the relevant fragment:

	/*	The following two print statements should be identical. 
		They aren't!. */

	int			i, j;
	MESH_PT		**mp = transform->mesh;		/* vector of pointers */

	for (j = -1; j <= transform->nj; ++j) {
		for (i = -1; i <= transform->ni; ++i) {
			printf("&mp[%d][%d] = %ld", j, i, (long)&mp[j][i]);
			printf("(mp[%d]+%d) = %ld", j, i, (long)(mp[j]+i));
		}
	}

(I appologize for the weird "-1" indexing -- it's for pointing into a 2D
array that has 1-point "margins" where mp[0][0] is the first, "true" data 
point.)

The results of the print statements were different (i.e. incorrect) under 
the VMS C compiler.  They were identical (i.e. correct) however, under 
both the GNU C and EUNICE C compilers.

The apparently incorrect behavior, however, was context sensitive.  When I
extracted the above fragment into its own program, I started getting
correct results.

Anyone else seen this?
-- 
Steve Emmerson                     Inet: steve at umigw.miami.edu [128.116.10.1]
SPAN: miami::emmerson (host 3074::)      emmerson%miami.span at star.stanford.edu
UUCP: ...!ncar!umigw!steve               emmerson%miami.span at vlsi.jpl.nasa.gov
"Computers are like God in the Old Testament: lots of rules and no mercy"



More information about the Comp.lang.c mailing list