473,396 Members | 1,703 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,396 software developers and data experts.

C++ linkage problems

Hi,

I read that identifiers should not start with an underscore in order to
prevent LINKAGE problems. I am not familar with this concept of "linkage",
so can someone provide a simple explanation?

Thanks in advance

WD

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.504 / Virus Database: 302 - Release Date: 24/07/2003
Jul 19 '05 #1
5 2762
In article <3f********@news.iprimus.com.au>,
Web Developer <no****@hotmail.com> wrote:
I read that identifiers should not start with an underscore in order to
prevent LINKAGE problems.
The strongest argument is that there are rules in the standard
that in a nushell say such names are only available for implementors,
in other words, for your compiler or library vendor.
I am not familar with this concept of "linkage",
so can someone provide a simple explanation?


Generally speaking, linkage applies to names of entities and
is one mechanism whereby implementations can disabmiguate their use.
In particular, when it needs to resolve where to uses of a name
refers to the same name. For instance, in external linkage,
the use of a "global" name in one translation unit (say a source file)
is considered to be the same name used in another translation
unit that will be linked together. It ties into scope and some
other things too. There is also static linkage and no linkage.
You should get a good C++ text and check out the section that
apply to this topics you raise in this email. Check out
http://www.comeaucomputing.com/booklist as one starting point.
--
Greg Comeau/ 4.3.0.1: FULL CORE LANGUAGE, INCLUDING TC1
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Jul 19 '05 #2
In article <aj************************@newssvr10.news.prodigy .com>,
Thomas Matthews <Th**************************@sbcglobal.net> wrote:
On one hand, there is no restriction against using symbols with leading
underscores....


I think you mean trailing?
--
Greg Comeau/ 4.3.0.1: FULL CORE LANGUAGE, INCLUDING TC1
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Jul 19 '05 #3
Greg Comeau wrote:
In article <aj************************@newssvr10.news.prodigy .com>,
Thomas Matthews <Th**************************@sbcglobal.net> wrote:
On one hand, there is no restriction against using symbols with leading
underscores....

I think you mean trailing?


No, I meant leading. A C++ compliant compiler will not generate
an error for the following line:
int __my_var;
provided that the defined variable doesn't exist as a public
symbol in the compiler's internals.

However, there may be a problem with the following definition:
int __FILE__;
Because __FILE__ is used by the compiler (actually the preprocessor).

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 19 '05 #4
In article <5X************************@newssvr10.news.prodigy .com>,
Thomas Matthews <Th**************************@sbcglobal.net> wrote:
Greg Comeau wrote:
In article <aj************************@newssvr10.news.prodigy .com>,
Thomas Matthews <Th**************************@sbcglobal.net> wrote:
On one hand, there is no restriction against using symbols with leading
underscores....
I think you mean trailing?


No, I meant leading. A C++ compliant compiler will not generate
an error for the following line:
int __my_var;
provided that the defined variable doesn't exist as a public
symbol in the compiler's internals.


2.10 and 17.4.3.1.2 clearly label this as a restriction.
Of course, certain "errors" need not result in a diagnostic,
but that's a seperate issue.
However, there may be a problem with the following definition:
int __FILE__;
Agreed. See above.
Because __FILE__ is used by the compiler
s/used/may be used/

Because __FILE__ begins with two underscores, and Standard C++
reads "Each name that contains a double underscore (_ _) ...
is reserved to the implementation for any use."
(actually the preprocessor).


Perhaps.
--
Greg Comeau/ 4.3.0.1: FULL CORE LANGUAGE, INCLUDING TC1
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Jul 19 '05 #5

Web Developer wrote:
Hi,

I read that identifiers should not start with an underscore in order to
prevent LINKAGE problems. I am not familar with this concept of "linkage", so can someone provide a simple explanation?


Symbols starting with an underscore are reserved for the compiler or
implementation. A programmer's symbol should not start with an
underscore to prevent name clashes or conflicts with compiler symbols.

What do you mean by implementation?
WD

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.504 / Virus Database: 302 - Release Date: 24/07/2003
Jul 19 '05 #6

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

Similar topics

9
by: qazmlp | last post by:
const has internal linkage in C++, but external linkage in C. Am I right ? But, linker reports multiply-defined error if the following header is included in multiple .cpp files. //...
47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
20
by: Grumble | last post by:
Hello everyone, As far as I understand, the 'inline' keyword is a hint for the compiler to consider the function in question as a candidate for inlining, yes? What happens when a function with...
7
by: Generic Usenet Account | last post by:
I am implementing a library that can be linked in with C as well as C++ code. Obviously, the library API is functional, but in my implementation I am using STL. Because of this, my code is...
10
by: Mark A. Gibbs | last post by:
I have a question about mixing C and C++. In a C++ translation unit, I want to define a function with internal linkage and C calling convention. Here's a sample of what I want to do: //...
3
by: al.cpwn | last post by:
do static and inline functions or members have internal linkage? I have been reading this newsgroup on google and found conflicting ideas. Can someone please help me understand why in some places...
13
by: fctk | last post by:
source: http://rm-f.net/~orange/devel/specifications/c89-draft.html#3.1.2.2 there are two passages in this paragraph i can't fully understand: 1) "If the declaration of an identifier for an...
3
by: catphive.lists | last post by:
I have a bunch of function object classes of the form struct MyFunc : unary_function<arg,ret> { MyFunc(arg) : state(arg) {} void operator() (arg) { /*code here*/ } }; in various cpp files....
4
by: Bart Simpson | last post by:
I m getting a ton of linkage errors (unresolved externals) when using an abstract base class. My classes look something like this: class BaseObject { //pure virtuals virtual void foo() = 0;...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...
0
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,...

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.