Question about VMS C
David R. Stampf
drs at bnlux0.bnl.gov
Tue Aug 30 22:51:03 AEST 1988
In article <32725 at cca.CCA.COM> g-rh at CCA.CCA.COM (Richard Harter) writes:
>
> The following came up on VMS C. Either my understanding of
>C is wrong, or the compiler is broken. The code ran as follows:
>
>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.
>
The gnomes at DEC seemed to have really screwed the C compiler in
its latest release. I wouldn't trust *any* code that uses double subscripting
at all. For example, the following "textbook" code also crashes and burns:
main ()
{
static char *char_tab[] =
{
"Monday",
"Tuesday"
};
int i,j;
for (i = 0; i < 2; i++)
for (j = 0; j < 4; j++)
printf("'%c' '%c'\n",char_tab[i][j],*(char_tab[i] + j));
}
If you compile it with the optimization off, it produces the correct
output. Using all of the defaults in compiling however produces completely
erroneous values for the char_tab[i][j] output. Makes you kind of
uncomfortable with the rest of their compiler.
This was compiled with the latest version of their compiler -
V2.4 and under VMS 4.7. It worked with the previous release of the compiler
and is still broken under VMS 5.0. I've reported this error to DEC, but
I haven't heard a thing from them other than it also failed on their
machines.
You may want to report this as well and find a better C compiler.
< dave stampf
More information about the Comp.lang.c
mailing list