By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,655 Members | 1,005 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,655 IT Pros & Developers. It's quick & easy.

C++ linkage problems

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.