What is the linkage of a namespace scope typedef?

R

red floyd

What is the linkage of a namespace scope typedef? Is it internal or
external?

3.5 is unclear on this.

In other words, is the following program, consisting of translation
units a.cpp and b.cpp, well formed?

a.cpp
// file a.cpp
typedef int MyType;
MyType x = 0;

b.cpp:
// file b.cpp

typedef double MyType;
MyType y = 0.0;

int main() { }
 
V

Victor Bazarov

red said:
What is the linkage of a namespace scope typedef? Is it internal or
external?

3.5 is unclear on this.

In other words, is the following program, consisting of translation
units a.cpp and b.cpp, well formed?

a.cpp
// file a.cpp
typedef int MyType;
MyType x = 0;

b.cpp:
// file b.cpp

typedef double MyType;
MyType y = 0.0;

int main() { }

AFAICT, a 'typedef-name' is a pure compile-time thing and it does
not have linkage (similar to macros). The program above is therefore
well-formed.

V
 
J

Jonathan Mcdougall

red said:
What is the linkage of a namespace scope typedef? Is it internal or
external?

3.5 is unclear on this.

Well §8 is pretty clear to me: "If a declaration uses a typedef name,
it is the linkage of the type name to which the typedef refers that is
considered."

A typedef is nothing more than syntactic sugar.
In other words, is the following program, consisting of translation
units a.cpp and b.cpp, well formed?

a.cpp
// file a.cpp
typedef int MyType;
MyType x = 0;

b.cpp:
// file b.cpp

typedef double MyType;
MyType y = 0.0;

int main() { }

Yes it is.


Jonathan
 
R

red floyd

Jonathan said:
Well §8 is pretty clear to me: "If a declaration uses a typedef name,
it is the linkage of the type name to which the typedef refers that is
considered."

A typedef is nothing more than syntactic sugar.

Yeah, I looked at 8 too, and it was just a hard parse for me.

Thanks Victor and Jonathan.
 
R

red floyd

Jonathan said:
Well §8 is pretty clear to me: "If a declaration uses a typedef name,
it is the linkage of the type name to which the typedef refers that is
considered."

To be honest, I had also considered 3.5/8, but still was uncertain.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top