delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/04/01/06:27:42

Date: Fri, 01 Apr 1994 05:43:41 -0500 (EST)
From: "Wonkoo Kim, EE, U. of Pittsburgh" <WKIM AT vms DOT cis DOT pitt DOT edu>
Subject: storage allocation of global var
To: djgpp AT sun DOT soe DOT clarkson DOT edu

Hi.

[Sorry that this is a general question rather than djgpp specific.]

When I declared a global variable that is used in several separate sources,
I always put 'extern' to sources except the first source file.  But, even if
I omitted 'extern', I didn't get any warning or error for doublely declared
global variable. (compiled with -Wall) 

For example, two files, main.c and test.c, both have the following line:

  #include "test.h"

and, a global variable is declared in test.h:

  int global_var;

I compiled *.c separetely and then linked them, (with -Wall compile),
and I didn't have any warning message for double declarations.

My question is, 

1. Is there no storage loss?  (i.e., Is the storage for 'global_var'
   allocated only once and shared by both main.c and test.c?)

2. If there is no storage loss, the linker handled this and merged
   the storage allocation for the same symbol, didn't it. (obviously)

Thanks.

Wonkoo Kim
wkim AT vms DOT cis DOT pitt DOT edu


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019