[Info-vax] Possible C compiler static variable initialization problem.
Simon Clubley
clubley at remove_me.eisner.decus.org-Earth.UFP
Wed Feb 26 13:40:54 EST 2014
On 2014-02-26, Simon Clubley <clubley at remove_me.eisner.decus.org-Earth.UFP> wrote:
> On 2014-02-26, Bob Koehler <koehler at eisner.nospam.encompasserve.org> wrote:
>> In article <leko68$egf$1 at dont-email.me>, Simon Clubley <clubley at remove_me.eisner.decus.org-Earth.UFP> writes:
>>>
>>> On VMS, variables defined in different source files, but with the same name,
>>> were traditionally treated as different variables by the linker and space
>>> allocated for each variable definition.
>>
>> I've been working with C on VMS since early VAX C days, and I've
>> never seen that. A file level variable (outside of any function)
>> is treats as global to the code unless it's specificially declared
>> static.
>>
>
> My apologies for the wrong information than.
>
> I encountered this back in the 90s with a C compiler and I had thought it
> was on VMS. I wonder if it was one of the early Microsoft C MS-DOS/Win 9x
> compilers which I worked with in that timeframe as well ?
>
I'm now really curious about this now I think I've remembered a bit more.
IIRC, on the C compiler in question you only had one declaration allowed
for a variable at file level and all the other file level declarations
in other source files _had_ to be extern references to the first
declaration.
After thinking about it a bit more, I cannot be sure anymore, if you tried
to define the variable twice at file level in different source files, if
the linker wrongly allocated additional space for the second variable
(like I stated above) or if it issued a multiple allocation error.
Anyone ever worked with a compiler like this and remember the compiler
and operating system ?
Thanks,
Simon.
PS: I've just tried it on Linux and binutils merged the two definitions
for "unsigned long int a;" in different source files together without
error just as expected and my test program treated them as one variable.
--
Simon Clubley, clubley at remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world
More information about the Info-vax
mailing list