|
|
Invisible <voi### [at] devnull> wrote:
> I see. So you still have to manually define what needs to be linked somehow?
How else is the compiler going to know which files are your source files?
By reading your mind?
> What I can't figure out is what happens if foo() is actually a function
> somewhere in the OS kernel. Presumably in each version of the kernel,
> the base address of this function is going to be different... so how the
> hell does the linker know what it is?
That's what dynamic linking is all about. That's why they are called
"dynamically linked libraries". The OS performs runtime linking when the
program is launched: It goes through the program and sets jump addresses
to their proper values.
And if the program uses a direct system call, it doesn't jump to some
address. It tells the OS "I want to make this system call" and the OS then
jumps there. The compiler (or more precisely, the system library the compiler
is using) knows how to tell the OS that.
> >> True... But I'm still wondering how VS does this in the absence of
> >> header files.
> >
> > Does what?
> Figures out what parts of the contents of a source file should be
> accessible from other files.
In C every global function which is not marked with the keyword 'static'
is accessible from anywhere. A function marked with 'static' is only
accessible from that same source file but not from anywhere else. (Yes,
reusing the keyword 'static' for this purpose is a kludge in the original
C specification.)
In C++ nameless namespaces are a cleaner way to achieve the same thing
(and then of course there exist completely different mechanics for class
member functions, which can be public or private).
> Like, if aux.c contains foo(), bar() and baz(), which of these should be
> available from elsewhere? Normally if you only wanted foo() to be
> public, you'd only put foo() in the header file. (And for God's sake
> remember to update the header file when foo() changes its type signature!)
Being in a header file is not what determines whether the function can
be called from the outside or not. In C, the keyword 'static' determines
that.
--
- Warp
Post a reply to this message
|
|