C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

7.1.2/4: static local variables of inline functions

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Vladimir Marko
Guest





PostPosted: Wed May 16, 2007 7:13 pm    Post subject: 7.1.2/4: static local variables of inline functions Reply with quote



Even in the most recent draft (n2284) the paragraph 7.1.2/4 says
... An inline function with external linkage shall have the same
address in all translation units. A static local variable in an
extern
inline function always refers to the same object. A string literal
in
an extern inline function is the same object in different
translation
units.
The wording makes a distinction between an "inline function with
external linkage" and an "extern inline function". Is this
intentional?
What about static local variables and string literals of inline
functions
with external linkage that are not explicitly declared extern -- do
they
cause undefined behaviour?

Best Regards,
Vladimir Marko

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
jg
Guest





PostPosted: Thu May 17, 2007 5:34 am    Post subject: Re: 7.1.2/4: static local variables of inline functions Reply with quote



On May 16, 12:13 pm, Vladimir Marko <swe...@post.sk> wrote:
Quote:
Even in the most recent draft (n2284) the paragraph 7.1.2/4 says
... An inline function with external linkage shall have the same
address in all translation units. A static local variable in an
extern
inline function always refers to the same object. A string literal
in
an extern inline function is the same object in different
translation
units.
The wording makes a distinction between an "inline function with
external linkage" and an "extern inline function". Is this
intentional?
What about static local variables and string literals of inline
functions
with external linkage that are not explicitly declared extern -- do
they
cause undefined behaviour?

Best Regards,
Vladimir Marko

Isn't an inline function with external linkage the same as extern

inline function ?!

JG

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Vladimir Marko
Guest





PostPosted: Fri May 18, 2007 5:01 pm    Post subject: Re: 7.1.2/4: static local variables of inline functions Reply with quote



On 17 May, 06:34, jg <jgu...@gmail.com> wrote:
Quote:
On May 16, 12:13 pm, Vladimir Marko <swe...@post.sk> wrote:

Even in the most recent draft (n2284) the paragraph 7.1.2/4 says
... An inline function with external linkage shall have the same
address in all translation units. A static local variable in an
extern
inline function always refers to the same object. A string literal
in
an extern inline function is the same object in different
translation
units.
The wording makes a distinction between an "inline function with
external linkage" and an "extern inline function". ...

Isn't an inline function with external linkage the same as extern
inline function ?!

The problem is that the quoted paragraph uses the _keywords_
"inline" and "extern" (printed in a different font) and thus implies
that the part about static local variables and string literals
applies only to inline functions explicitly declared extern.
If this is not the intent, the paragraph should be reworded.

See recent thread "singleton initialization" in clc++m,
struct singleton{
static singleton& instance(){ // implicitly inline
static singleton s; // undefined behaviour?
return s;
}
};

Regards,
Vladimir Marko

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Greg Herlihy
Guest





PostPosted: Fri May 18, 2007 5:08 pm    Post subject: Re: 7.1.2/4: static local variables of inline functions Reply with quote

On 5/16/07 12:13 PM, in article
1179338900.300634.262940 (AT) u30g2000hsc (DOT) googlegroups.com, "Vladimir Marko"
<swelef (AT) post (DOT) sk> wrote:

Quote:
Even in the most recent draft (n2284) the paragraph 7.1.2/4 says
... An inline function with external linkage shall have the same
address in all translation units. A static local variable in an
extern
inline function always refers to the same object. A string literal
in
an extern inline function is the same object in different
translation
units.
The wording makes a distinction between an "inline function with
external linkage" and an "extern inline function". Is this
intentional?

What distinction? There is nothing in these three sentences to suggest that
an "extern inline function" and an "inline function with external linkage"
are anything but synonymous. A distinction would require that both terms
appear in a single sentence with some kind of qualifier separating them,
such as "but...", "except...", "provided that...". But as currently worded,
these three sentences are completely independent of each other.

Quote:
What about static local variables and string literals of inline
functions
with external linkage that are not explicitly declared extern -- do
they
cause undefined behaviour?

In C++, if a function is not extern then it must be static. And local
variables and string literals are well-defined in both types of functions,
so the answer is "no."

Greg

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
James Kanze
Guest





PostPosted: Fri May 18, 2007 5:11 pm    Post subject: Re: 7.1.2/4: static local variables of inline functions Reply with quote

On May 16, 9:13 pm, Vladimir Marko <swe...@post.sk> wrote:
Quote:
Even in the most recent draft (n2284) the paragraph 7.1.2/4 says
... An inline function with external linkage shall have the same
address in all translation units. A static local variable in an
extern
inline function always refers to the same object. A string literal
in
an extern inline function is the same object in different
translation
units.
The wording makes a distinction between an "inline function with
external linkage" and an "extern inline function". Is this
intentional?
What about static local variables and string literals of inline
functions
with external linkage that are not explicitly declared extern -- do
they
cause undefined behaviour?

I think this is just editorial. If I'm not mistaken, this text
hasn't changed since the original standard, perhaps not even
since the ARM. In the ARM, an inline function had internal
linkage unless it was explicitly declared extern. (Note that
the text you quote is in a certain sense a comment. There's
nothing in the rest of the text which authorizes the compiler to
treat an inline function differently from any other function in
these regards.)

--
James Kanze (GABI Software) email:james.kanze (AT) gmail (DOT) com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
James Kanze
Guest





PostPosted: Sun May 20, 2007 3:58 am    Post subject: Re: 7.1.2/4: static local variables of inline functions Reply with quote

On May 18, 7:08 pm, Greg Herlihy <gre...@pacbell.net> wrote:
Quote:
On 5/16/07 12:13 PM, in article
1179338900.300634.262...@u30g2000hsc.googlegroups.com, "Vladimir Marko"

swe...@post.sk> wrote:
Even in the most recent draft (n2284) the paragraph 7.1.2/4 says
... An inline function with external linkage shall have the same
address in all translation units. A static local variable in an
extern
inline function always refers to the same object. A string literal
in
an extern inline function is the same object in different
translation
units.
The wording makes a distinction between an "inline function with
external linkage" and an "extern inline function". Is this
intentional?

What distinction? There is nothing in these three sentences to suggest that
an "extern inline function" and an "inline function with external linkage"
are anything but synonymous.

There's nothing to suggest that they are the same. In the
actual text in the standard, the words "extern" and "inline" are
in typewriter font, which generally means that the keywords are
meant. (For that matter, I don't think that there is a word
"extern" in the English language.) Thus, the text very strongly
suggests that it is the presence of the keywords in the
declaration which is important, and not the actual linkage
(which is "external", and not "extern").

Historically, inline functions had internal linkage, unless
explicitly declared extern, so this distinction didn't make a
difference; an inline function had external linkage if and only
if it was declared "extern". This was changed sometime in the
1990's, however, and today, inline functions have external
linkage by default.

Quote:
A distinction would require that both terms
appear in a single sentence with some kind of qualifier separating them,
such as "but...", "except...", "provided that...". But as currently worded,
these three sentences are completely independent of each other.

What about static local variables and string literals of inline
functions
with external linkage that are not explicitly declared extern -- do
they
cause undefined behaviour?

In C++, if a function is not extern then it must be static.

Not at all. Where do you get that from? I rarely declare
a function either.

Don't confuse keywords that appear in the declaration (such as
extern) and linkage: extern and static are keywords, where as
the linkage may be external, internal or none. A function
declared at namespace scope has external linkage, even in the
absence of a keyword, and a function declared at class scope has
external linkage, even if it is static.

--
James Kanze (Gabi Software) email: james.kanze (AT) gmail (DOT) com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
 


Powered by phpBB © 2001, 2006 phpBB Group