Category : C++ Source Code
Archive   : C_ALL.ZIP
Filename : TI1019.ASC

 
Output of file : TI1019.ASC contained in archive : C_ALL.ZIP







PRODUCT : Borland C++ NUMBER : 1019
VERSION : 3.1
OS : ALL
DATE : December 3, 1992 PAGE : 1/2

TITLE : Using COMDEFs with v3.x of BC++





COMDEFs are an extension to C. They enable a programmer to
link modules containing duplicate uninitialized global variables
that are not declared as extern and not get any duplicate symbol
errors.

Variables used in this manner are also known as communal
variables.

For example,

FOO.C: int i; BAR.C: int i;
main() test()
{ {
} }

If we have 'OPTIONS|COMPILER|ADVANCED CODE
GENERATION|OPTIONS|GENERATE COMDEFs' enabled, then the above code
will generate only one instance of i, and the modules will link
together with no errors.

With COMDEFs disabled, one of the "int i;" declarations needs
to have the keyword extern in order to get past the linker.

Additionally, if one of the declarations for i is initialized
(such as "int i = 1;"), then COMDEFs will not apply for i, and
duplicate symbols will result if declarations of i in other
modules are not declared as extern.

Borland has COMDEFs disabled by default since they are an
extension to C and are not part of the ANSI C standard. (Several
PC Compiers have COMDEFs enabled by default). According to ANSI,
the above code is illegal. However, with Borland's Generate
COMDEFs option enabled, the above code is accepted by the linker.

COMDEFs are not supported under C++ because uninitialized
global variables are treated in C++ as though they were
initialized to zero. (All global objects have storage class
static, and all uninitialized static variables are implicitly
initialized to zero.)
















PRODUCT : Borland C++ NUMBER : 1019
VERSION : 3.1
OS : ALL
DATE : December 3, 1992 PAGE : 2/2

TITLE : Using COMDEFs with v3.x of BC++.




For more information on C++ uninitialized global variables,
see sections 3.5 and 8.4 in Ellis & Stroustrup's The Annotated
C++ Reference Manual (1990, Addison-Wesley).

The most likely problem that one would run into with communal
variables is the error message

ERROR: defined in module is duplicated in module

If you must use C++, you may not use COMDEFs because C++ does
not support them. Use the keyword 'extern' (as explained
above) instead of using COMDEFs and multiple declarations. If
you don't need to use C++ and still want to use COMDEFs, switch
to using C.



DISCLAIMER: You have the right to use this technical information
subject to the terms of the No-Nonsense License Statement that
you received with the Borland product to which this information
pertains.






























  3 Responses to “Category : C++ Source Code
Archive   : C_ALL.ZIP
Filename : TI1019.ASC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/