🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #5482

Re: A Little Quibble

#5482
From: mcdaniel
Date: Thu, 08 Dec 1988 23:01
46 lines
1757 bytes
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@uicsrd.csrd.uiuc.edu
Supercomputing  |||  UUCP:     {uunet,convex,pur-ee}!uiucuxc!uicsrd!mcdaniel
Research and    |||  ARPANET:  mcdaniel%uicsrd@uxc.cso.uiuc.edu
Development,    |||  CSNET:    mcdaniel%uicsrd@uiuc.csnet
U of Illinois   |||  DECnet:   GARCON::"mcdaniel@uicsrd.csrd.uiuc.edu"
Technical Details
Message-ID: <25200002@uicsrd.csrd.uiuc.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!tmsoft!dptcdc!dpmizar!swrinde!cs.utexas.edu!rutgers!deimos!uxc!uxc.cso.uiuc.edu!uxg.cso.uiuc.edu!uicsrd.csrd.uiuc.edu!mcdaniel
References: <25200001@uicsrd.csrd.uiuc.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!tmsoft!dptcdc!dpmizar!swrinde!cs.utexas.edu!rutgers!deimos!uxc!uxc.cso.uiuc.edu!uxg.cso.uiuc.edu!uicsrd.csrd.uiuc.edu!mcdaniel
From: mcdaniel@uicsrd.csrd.uiuc.edu
Newsgroups: comp.std.c
Subject: Re: A Little Quibble
Message-ID: <25200002@uicsrd.csrd.uiuc.edu>
Date: 8 Dec 88 23:01:00 GMT
References: <25200001@uicsrd.csrd.uiuc.edu>
Lines: 46
Nf-ID: #R:uicsrd.csrd.uiuc.edu:25200001:uicsrd.csrd.uiuc.edu:25200002:000:1196
Nf-From: uicsrd.csrd.uiuc.edu!mcdaniel    Dec  8 17:01:00 1988