A Little Quibble

mcdaniel at uicsrd.csrd.uiuc.edu mcdaniel at uicsrd.csrd.uiuc.edu
Fri Dec 9 09:01:00 AEST 1988


Please excuse more of my quibbling . . .

Is the program below legal under dpANS?   Is it guaranteed to output 1?

#include <stdio.h>
int a = 1;
main()
    {
    int a = 2; /* Y */
        {
        extern int a; /* Z */
        printf("%d\n", a);
        }
    }

On the VAX BSD 4.3 compiler, it complaints about line Z (redeclaration
of a).  If line Y is changed to "extern int a;", though, it compiles
fine.

What if I change line Z to "extern const int a;"?


About my base note's program (here reprinted)
    #include <stdio.h>
    main() {
	int a; a = 1;
	{ int a = a; printf("a=%d\n", a); }
	exit(0);
	}

The BSD 4.3 compiler apparently evaluates the right-hand side of
	int a = a;
in the context of the current block (as if it were
	int a; a = a;
); this program does not output "1".

--

             Tim, the Bizarre and Oddly-Dressed Enchanter

Center for      |||  Internet, BITNET:  mcdaniel at uicsrd.csrd.uiuc.edu
Supercomputing  |||  UUCP:     {uunet,convex,pur-ee}!uiucuxc!uicsrd!mcdaniel
Research and    |||  ARPANET:  mcdaniel%uicsrd at uxc.cso.uiuc.edu
Development,    |||  CSNET:    mcdaniel%uicsrd at uiuc.csnet
U of Illinois   |||  DECnet:   GARCON::"mcdaniel at uicsrd.csrd.uiuc.edu"



More information about the Comp.std.c mailing list