473,795 Members | 3,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4403
"Torbak" <at*****@free.f r> 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", "DisplayTex t" and
of course "Talk".

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

Because for me, the "DisplayTex t" 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
"DisplayTex t" 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 afunctionDescri ptor // adress of my private func.
0XOOOyyy Talk(void)
...
call afunctionDescri ptor // 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", "DisplayTex t" and
of course "Talk".

I expected to find only my public "Talk" function and not the other
symbols like "DisplayText(in t)".
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 "DisplayTex t" 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
"DisplayTex t" 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 afunctionDescri ptor // adress of my private func.
0XOOOyyy Talk(void)
...
call afunctionDescri ptor // 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.ne t
Jul 19 '05 #8

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

Similar topics

1
2338
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 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...
4
2299
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 files from that library. If I choose to build the executable directly with only relevant source files, I know I do not bloat the executable with symbols and functions that are never used.
5
11696
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 on plot axes labels, etc. I would prefer something that adheres to tex formatting (as implemented in latex, matlab, etc and has the form $\alpha$ to represent the greek character alpha for example). thus far, i've found that matplotlib
3
2341
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
3371
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 are objects whose representation within the code is more important than their actual value. Two symbols needs only to be
6
2703
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 setting. They are in the same solution, and compile/link without problems (Debug configuration). I also have 1 mixed-mode CLR DLL that consumes both the static libraries and managed DLLs. It is configured to use the /MDd C Runtime library. When...
4
1279
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 preprocessor symbols edit box. Nothing was in there, presumably because no symbols are common to all selections, which is as expected. However, when I added the new symbol I found that _all_ other symbols, such as _WINDOWS etc. had been deleted from all...
1
2369
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 little background to how the system works right now. I am developing a module for Python. The original code is written in C++ and I am creating a wrapper using Boost.Python. The C++ code for the module makes calls into a library that in turn...
1
2832
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 binary. Problem is the due to diffrent # defines some functions behave diffrently. And sorce code need to be compiled in both ways. So I thought of a solution to change the name of symbols after compilation rename the library and link both library...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.