Discussion: Globals and Exports
Afficher un message
Vieux 05/05/2008, 15h00   #7
Antoninus Twink
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Globals and Exports

On 5 May 2008 at 11:12, Flash Gordon wrote:
> Antoninus Twink wrote, On 05/05/08 11:12:
>> On 5 May 2008 at 9:53, Bartc wrote:
>>> I noticed that in C, functions in any module are automatically exported. So
>>> that it's not possible to use the same function name in two modules (ie.
>>> source files).

>>
>> Check out your compiler's options. For example, gcc has quite a
>> sophisticated visibility model: in the simplest case, you can use
>> __attribute ((visibility("hidden"))) as a qualifier, or compile with
>> -fvisibility=hidden.

>
> So what is wrong with static? Why suggest a non-standard extension when
> a feature the language has had in all implementations for years is
> sufficient.


Because they do different things. If you're making a shared library,
then you might want to have variables and functions that are globally
visible within your library, but don't pollute the namespace for users
of your library. Gcc's __attributes can achieve that.

Without extensions, you have only two choices: either make a variable
static, and so visible only within a single translation unit, or else
make it globally visible everywhere. Compiler extensions can provide
finer-grained visibility control, which seems to be what the OP had in
mind: when you link your shared library, all uses of a symbol throughout
the library files are resolved, but that symbol isn't put into the table
of externally-visible symbols in your .so file.

  Réponse avec citation
 
Page generated in 0,06304 seconds with 9 queries