473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Symbols in library.

I got some question about symbols in libraries ...

In libraries, there is public symbols and "not public" symbols
(private, static)... In C when we use the "static" keyword on the
declaration of a function, the function is not public in the library.

1- When I use a class, all is symbols are put in the public section of
the library. How can I change that. The keyword "private" in a class
is only for the langage or does it change (like "static") something in
libs ? Even in object file ?

2- Even symbols which are not "static" have there decorated name in
the library. (I use bindump to check that). How can I avoid that for
the private functions of my lib ?
What COFF is use for then ?

3- The keyword "static" is used to keep the use of something in the
file scope. If my lib is composed from many object file, how can I
"hide" private functions ?

Does somebody know how I can get a good documentation about library
files ?
Thanks
Jul 19 '05 #1
7 4354
"Torbak" <at*****@free.fr> wrote...
I got some question about symbols in libraries ...

In libraries, there is public symbols and "not public" symbols
(private, static)... In C when we use the "static" keyword on the
declaration of a function, the function is not public in the library.
Actually, the term used in C++ is "external linkage" versus "internal
linkage". "Public" has a different meaning in C++.
1- When I use a class, all is symbols are put in the public section of
the library.
Are they? The C++ language specification says nothing about that.
How can I change that.
You need to ask in a newsgroup that deals with your particular
compiler because creation of libraries is not defined by C++ as a
language.
The keyword "private" in a class is only for the langage or does it
change (like "static") something in libs ? Even in object file ?
That is not defined by the language specification.
2- Even symbols which are not "static" have there decorated name in
the library. (I use bindump to check that). How can I avoid that for
the private functions of my lib ?
That is not defined either, however, some compilers will not decorate
functions that are specified 'extern "C"' or decorate them differently
if they are specified as 'extern "Pascal"' or something. Again, this
is not defined by the C++ language itself.
What COFF is use for then ?
There is no "COFF" in C++. Perhaps you need to ask your question in
a newsgroup where "COFF" is on topic.
3- The keyword "static" is used to keep the use of something in the
file scope.
Actually, for symbols declared 'static' in a namespace scope, it makes
them have internal linkage (those names are not visible from other
translation units).
If my lib is composed from many object file, how can I
"hide" private functions ?
C++ doesn't specify that, but the solution I've seen is to only expose
some base class with all public interface virtual and pure, and then
implement the functionality in derived classes. Access to the actual
functionality should be given through a pointer to the base class,
returned from some library function (factory function), and behind the
pointer to base should actually be an object of the derived class.
Does somebody know how I can get a good documentation about library
files ?


You should ask your compiler developer/manufacturer/vendor.

Victor
Jul 19 '05 #2
Torbak wrote:
I got some question about symbols in libraries ...
[posting from c.l.c++]

Standard C++ is silent on libraries, except to say that the standard
library exists and what it contains. Anything past that is a
platform/implementation issue.
Does somebody know how I can get a good documentation about library
files ?


Since library implementation is platform specific, platform
documentation is the way to go. <OT>For general info, John Levine's
"Linkers and Loaders" would be a good place to start.</OT>

HTH,
--ag
--
Artie Gold -- Austin, Texas
[Thanks, but he will indeed also need info on his particular platform.
-John]

Jul 19 '05 #3
On 31 Jul 2003 12:47:02 -0400, at*****@free.fr (Torbak) wrote:
I got some question about symbols in libraries ...

In libraries, there is public symbols and "not public" symbols
(private, static)... In C when we use the "static" keyword on the
declaration of a function, the function is not public in the library.

1- When I use a class, all is symbols are put in the public section of
the library. How can I change that.
If you can forget about "libraries" and "object files", which are not
specified by the C++ standard, the answer to what you probably intend
to ask is to use
* An anonymous namespace.
Example:
namespace // anon
{
class C
{
...
};
}
The keyword "private" in a class is only for the langage or does it
change (like "static") something in libs ? Even in object file ?
That, including the possible existence of libraries and object files,
depends on the compiler and linker (if a linker exists).
2- Even symbols which are not "static" have there decorated name in
the library. (I use bindump to check that). How can I avoid that for
the private functions of my lib ?
A literal interpretation of that question is meaningless.

Perhaps you mean: "Even when a non-member function is declared as
'static' I get a name conflict with another compilation unit". In
that case your compiler is broken. However, the mere presence of
a name in some compiled form of the C++ source does not mean that
there will be a name conflict, e.g., it might be debug information.

But most probably what you meant is literally what you wrote, which
means some confusion about the effect of the word 'static'.
What COFF is use for then ?
<ot>
COFF is an object file format. Use Google to find more info.
</ot>
3- The keyword "static" is used to keep the use of something in the
file scope.
Nope. 'static' has many different meanings depending on context.
If a non-member function or variable or constant is declared 'static'
then usage of that entity is restricted to the _compilation unit_,
which might comprise many files.

If my lib is composed from many object file, how can I "hide" private
functions ?
Interpretation: "How can avoid name clashes for functions that are
only used within one compilation unit?".

Most people just use 'static', at least, I _believe_ that's what most
people do. Some strictly standard-conforming people use anonymous
namespaces. That's because 'static' is deprecated for this usage, so
in some far-fetched theoretical sense it might stop working in version
3247.8 of some non-commercial experimental compiler, far in the future.

Does somebody know how I can get a good documentation about library
files ?


Start a new thread here, or search for old threads, about
documentation of the standard library, if that's what you mean.

You might also check the FAQ.

If you actually mean 'library files' as in '.lib files', that's
compiler- and system-specific, so check your compiler and system
documentation.

Jul 19 '05 #4
On 31 Jul 2003 12:47:02 -0400, at*****@free.fr (Torbak) wrote:
I got some question about symbols in libraries ...

In libraries, there is public symbols and "not public" symbols
(private, static)... In C when we use the "static" keyword on the
declaration of a function, the function is not public in the library.

1- When I use a class, all is symbols are put in the public section of
the library. How can I change that.
If you can forget about "libraries" and "object files", which are not
specified by the C++ standard, the answer to what you probably intend
to ask is to use
* An anonymous namespace.
Example:
namespace // anon
{
class C
{
...
};
}
The keyword "private" in a class is only for the langage or does it
change (like "static") something in libs ? Even in object file ?
That, including the possible existence of libraries and object files,
depends on the compiler and linker (if a linker exists).
2- Even symbols which are not "static" have there decorated name in
the library. (I use bindump to check that). How can I avoid that for
the private functions of my lib ?
A literal interpretation of that question is meaningless.

Perhaps you mean: "Even when a non-member function is declared as
'static' I get a name conflict with another compilation unit". In
that case your compiler is broken. However, the mere presence of
a name in some compiled form of the C++ source does not mean that
there will be a name conflict, e.g., it might be debug information.

But most probably what you meant is literally what you wrote, which
means some confusion about the effect of the word 'static'.
What COFF is use for then ?
<ot>
COFF is an object file format. Use Google to find more info.
</ot>
3- The keyword "static" is used to keep the use of something in the
file scope.
Nope. 'static' has many different meanings depending on context.
If a non-member function or variable or constant is declared 'static'
then usage of that entity is restricted to the _compilation unit_,
which might comprise many files.

If my lib is composed from many object file, how can I "hide" private
functions ?
Interpretation: "How can avoid name clashes for functions that are
only used within one compilation unit?".

Most people just use 'static', at least, I _believe_ that's what most
people do. Some strictly standard-conforming people use anonymous
namespaces. That's because 'static' is deprecated for this usage, so
in some far-fetched theoretical sense it might stop working in version
3247.8 of some non-commercial experimental compiler, far in the future.

Does somebody know how I can get a good documentation about library
files ?


Start a new thread here, or search for old threads, about
documentation of the standard library, if that's what you mean.

You might also check the FAQ.

If you actually mean 'library files' as in '.lib files', that's
compiler- and system-specific, so check your compiler and system
documentation.

Jul 19 '05 #5
Thanks for thoses answers.

About :
"2- Even symbols which are not "static" have there decorated name in
the library. (I use bindump to check that). How can I avoid that for
the private functions of my lib ?", in fact I make a mistake. I
should say "Even symbols wich ARE 'static' have there ..."

I fact my question should be shortly discribe like this : Libraries
are files wich contain compiled code. Then to be linked, they contain
symboles description to discribe to the linker where it can find
functions which are accesible in the library. When I programme my
lib, I distingue 2 types of functions : those which will be "public",
means appear in header file, could be called from other compomnent of
the prog ... And those wich should not be called by others.

ex :
/* private stuff */
static char textTab[] = {"Hello", "By" };
static void DisplayText( int i ) {
sprintf("I say :%s/n", textTab[i&1] );
}

/* public stuff */
void Talk( void ) {// my public function
int i = rand();
DisplayText(i); // call private function
}
in mylib.h
extern "C" void Talk( void );

When I compile my stupid lib (I don't checked if what I wrote is
good), in release mode with no debug information etc ... I'll find
all symbols in the lib using dumpbin ... "textTab", "DisplayText" and
of course "Talk".

I expected to find only my public "Talk" function and not the other
symbols like "DisplayText(int)".

Because for me, the "DisplayText" function should be linked directly
in the library, and no any information about it should appear in the
release object. I wounder find the same thing than if the
"DisplayText" function was not exist like : void Talk( void ) {// my
is alone. No call to "private" functions.
sprintf("I say :%s/n", textTab[rand()&1] );
}
Of course, this exemple is simple because my private function is
called one time, and could be inlined.
So in general I wounder something like this :
0x000xxx afunctionDescriptor // adress of my private func.
0XOOOyyy Talk(void)
...
call afunctionDescriptor // call or jmp ...
ret

So if I use long description function name and many little functions,
my lib will be larger than if I use short function name with big
functions ?

I use microsoft C compiler.

PS : I tried namespaces but it doen't change anything.
Jul 19 '05 #6
at*****@free.fr (Torbak) wrote in message news:<03*******@comp.compilers>...
I got some question about symbols in libraries ...
1- When I use a class, all is symbols are put in the public section of
the library. How can I change that. The keyword "private" in a class
is only for the langage or does it change (like "static") something in
libs ? Even in object file ?

The private keyword refers to members (data or function) which can
only be accessed by members of that class- as per ANSI C++ standard.
2- Even symbols which are not "static" have there decorated name in
the library. (I use bindump to check that). How can I avoid that for
the private functions of my lib ?
What COFF is use for then ?

neither non-members within the library nor outside can access them
even if they see it , if they have been defined to be private. The
static keyword inside a class has a (slightly) different meaning. eg:-
class C {
public:
int value;
....
};

unless you define an instance of class C, you will not be anle to set
the value.
with static, you can.
class C {
public:
static int value;
...
};
class C::value = 1 is valid because there is no instance required.
Further, there is only one copy of the variable no matter how many
instances of the class C have been defined/malloc()'ed.

The ANSI C++ compiler makes no attempt to hide the field from
functions outside the scope of the C++ file where it is defined.
3- The keyword "static" is used to keep the use of something in the
file scope. Oustide the class/struct, if the static keyword is used, yes that is
what it is supposed to do. If my lib is composed from many object file, how can I
"hide" private functions ?


Depends on whether you want to prevent access or hide info about
symbol names.
As another poster stated, you may want to use the external/internal
linkage stuff for the latter.

regards
-kamal
Jul 19 '05 #7
On 20 Aug 2003 01:20:22 -0400, at*****@free.fr (Torbak) wrote:
Thanks for thoses answers.

About :
"2- Even symbols which are not "static" have there decorated name in
the library. (I use bindump to check that). How can I avoid that for
the private functions of my lib ?", in fact I make a mistake. I
should say "Even symbols wich ARE 'static' have there ..."

[later] I use microsoft C compiler.
I thought the MS tool was dumpbin, not bindump. I don't know about MS
object format in particular, but many object formats can record both
symbols which are "visible" to and can be linked from other modules,
usually called "global" or "external", and also symbols which are are
still generated but cannot be linked and do not conflict with other
such symbols having the same namem, "local" or "internal". In
traditional Unix 'nm', the letter for symbol type is uppercase for
global (T=text, D=data, B=bss) and lowercase for local (t,d,b).
I fact my question should be shortly discribe like this : Libraries
are files wich contain compiled code. Then to be linked, they contain
symboles description to discribe to the linker where it can find
functions which are accesible in the library. When I programme my
lib, I distingue 2 types of functions : those which will be "public",
means appear in header file, could be called from other compomnent of
the prog ... And those wich should not be called by others.
Noting that this use of 'public' and 'private' is different from,
though somewhat similar to, the same-named access modifiers for
members of a class (or struct) in C++. (And also Java.)
ex :
/* private stuff */
static char textTab[] = {"Hello", "By" };
That doesn't agree in type. You wanted char * text [].
And the opposite of Hello should be Bye or Good-bye.
static void DisplayText( int i ) {
sprintf("I say :%s/n", textTab[i&1] );
The first argument to sprintf must be a buffer (char array) of
sufficient size into which the formatted result is written. You
apparently want printf. And /n is not a newline, \n is.
}

/* public stuff */
void Talk( void ) {// my public function
int i = rand();
DisplayText(i); // call private function
}
in mylib.h
extern "C" void Talk( void );

When I compile my stupid lib (I don't checked if what I wrote is
good), in release mode with no debug information etc ... I'll find
all symbols in the lib using dumpbin ... "textTab", "DisplayText" and
of course "Talk".

I expected to find only my public "Talk" function and not the other
symbols like "DisplayText(int)".
See above; you need to find the doc or a newsgroup for your particular
compiler/implementation/platform to check that the DisplayText you see
is harmlessly local, and if there is a way to not generate it at all.
Because for me, the "DisplayText" function should be linked directly
in the library, and no any information about it should appear in the
release object. I wounder find the same thing than if the
"DisplayText" function was not exist like : void Talk( void ) {// my
is alone. No call to "private" functions.
sprintf("I say :%s/n", textTab[rand()&1] );
}
Of course, this exemple is simple because my private function is
called one time, and could be inlined.
A function definition earlier in the same (preprocessed) source file
certainly can be inlined, if the compiler implements it; the compiler
may require an option to do inlining (check you doc) and must have
limits where if a called function is too big or contains certain kinds
of complexity it won't be inlined, although I would expect your very
simple example not to exceed any reasonable limits.
So in general I wounder something like this :
0x000xxx afunctionDescriptor // adress of my private func.
0XOOOyyy Talk(void)
...
call afunctionDescriptor // call or jmp ...
ret

So if I use long description function name and many little functions,
my lib will be larger than if I use short function name with big
functions ?
If you use lots of little functions, they will almost certainly
generate more code, as well as (much) more object-file structuring
information, and more debugging symbols if you generate those, which
is rarely the default, than the same functionality in fewer functions.

If you use longer names for functions, it won't change the actual
code; it will probably make the object-file structuring information
slightly larger, and debugging symbols if any slightly larger.

Object-file structuring information won't (in any case I know of)
affect the size of the actual runtime code, and on many systems
debugging symbols (if they exist at all) are not actually loaded at
runtime unless you actually use the debugger.
PS : I tried namespaces but it doen't change anything.


That's surprising; symbols in namespaces (other than the global
namespace) need to be fixed somehow so that e.g. foo::x and bar::x do
not conflict; usually if not always this is done by "mangling" the
name. Possibly the tool you are using automatically demangles the
names before displaying them; check for an option to suppress that.

- David.Thompson1 at worldnet.att.net
Jul 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Torbak | last post by:
I got some question about symbols in libraries ... In libraries, there is public symbols and "not public" symbols (private, static)... In C when we use the "static" keyword on the declaration of...
4
by: Sam Smith | last post by:
Hi, I'm thinking about whether or not to build a general library on its own and later link that lib with the main executable, or to build the main executable with a subset of the relevant source...
5
by: michael.s.gilbert | last post by:
hello all, this message is geared toward those of you in the scientific community. i'm looking for a python plotting library that can support rendering greek symbols and other various characters...
3
by: Mathieu Malaterre | last post by:
Hello, I have currently a piece a code which look like this: foo.h ------------------- extern const std::string NotFound; foo.cxx
47
by: Pierre Barbier de Reuille | last post by:
Please, note that I am entirely open for every points on this proposal (which I do not dare yet to call PEP). Abstract ======== This proposal suggests to add symbols into Python. Symbols...
6
by: John | last post by:
I have 5 native static libraries that are being compiled in Visual Studio 2005 with the /MDd C Runtime option. I have 2 CLR DLLs (all managed code) in Visual Studio 2005 and the /MDd C Runtime...
4
by: David W | last post by:
In VS .NET 2003 (SP1) I wanted to add a preprocessor symbol to all configurations of all projects in a solution. I selected all the projects and then went to Properties, where I went to the...
1
by: dfj225 | last post by:
While my question doesn't pertain specifically to python programming, it is a result of developing a python module, so I'm hoping someone here might have experience with this issue. So, first a...
1
by: swapniliit2222 | last post by:
Hi I have a little problem, I have a source code which need to be compiled in two diffrent ways With some diffrent # defines in both cases. And I need to link both library to link to the same...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.