delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/09/21/06:46:57

To: Henrik Storner <storner AT olicom DOT dk>
Cc: S_Eckart AT lis DOT e-technik DOT tu-muenchen DOT de (Stefan Eckart),
djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: strange linker behavior
Date: Wed, 21 Sep 94 09:22:11 +0200
From: eliz AT is DOT elta DOT co DOT il

> So the 'delay' variable is uninitialized, and the output is therefore random.
> Indeed, changing the declaration in your sample program to
> 
>	static int delay;
>
> produces '0' as output, with DJGPP 1.12.maint2.

As others have already replied, `delay' should be zero even if not
declared static, because it is declared outside any function.  The
`static' thing only makes it private to the source file it is
declared in, and therefore avoids the ``bug'' caused by its linkage
to the library-defined name.  In addition to what've been said about
this by others, there is a lesson here: any global variable which is
not used across source files, should be *always* declared static, to
minimize a possibility of a name clash with other global symbols.
Being defensive never hurts much, but generally helps a lot.

	Eli Zaretskii

- Raw text -


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