Re: how to export global variable in C dll?
"Cyrfer" wrote:
I think the fundamental lesson you were able to teach me is that
'declaring' is different from 'defining' ?
Yes, a declaration is not always a definition. The C++ standard
puts it succinctly:
<quote>
3.1 Declarations and definitions [basic.def]
1 A declaration introduces names into a translation unit or
redeclares names introduced by previous declarations. A
declaration specifies the interpretation and attributes of these
names.
2 A declaration is a definition unless it declares a function
without specifying the function's body, it contains the `extern'
specifier or a linkage-specification and neither an initializer
nor a function-body, it declares a static data member in a class
declaration, it is a class name declaration, or it is a typedef
declaration, a using-declaration, or a using-directive.
</quote>
Then there goes the list of examples of definitions and
declarations.
I mean, to export global variables in C DLLs, you need a header
file that declares the variable names in which the DLL and
client code will both reference (declared with extern). But
also, you need an implementation file that 'defines' the
variables (not using extern) - I've not been introduced to this
concept before.
You are correct. You need the `extern' specifier before the name
of a global variable to introdice a level of indirection. So, when
the name is used, the compiler will put a pointer to a definition,
which is resolved by linker later on.
Alex