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 

Declaration or Definition

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
newmans
Guest





PostPosted: Sat Jun 26, 2004 2:23 am    Post subject: Declaration or Definition Reply with quote



Perhaps one of the experts can straighten me out on this point...

In Bjarne Stroustrup's book 'The C++ Programming Language' 3rd Edition,
section 4.9, indicates that

typedef complex<short> Point;

is not only a declaration, but also a definition.

The ISO/IEC 14882:2003(E) standard states in section 3.1 clause 2 that

"A declaration is a definition unless it declares a function without
specifying the function's body (8.4),
it contains the extern specifier (7.1.1) or a linkage-specification24) (7.5)
and neither an initializer nor a function-body,
it declares a static data member in a class declaration(9.4),
it is a class name declaration (9.1),
or it is a typedef declaration (7.1.3),
a using-declaration (7.3.3),
or a using-directive (7.3.4)".

So my question is , based on the (7.3.3) line of the clause, why is the
typedef
above a definition?


Newman


Back to top
Phlip
Guest





PostPosted: Sat Jun 26, 2004 2:49 am    Post subject: Re: Declaration or Definition Reply with quote



newmans wrote:

Quote:
Perhaps one of the experts can straighten me out on this point...

In Bjarne Stroustrup's book 'The C++ Programming Language' 3rd Edition,
section 4.9, indicates that

typedef complex<short> Point;

is not only a declaration, but also a definition.

The ISO/IEC 14882:2003(E) standard states in section 3.1 clause 2 that

"A declaration is a definition unless it declares a function without
specifying the function's body (8.4),
it contains the extern specifier (7.1.1) or a linkage-specification24)
(7.5)
and neither an initializer nor a function-body,
it declares a static data member in a class declaration(9.4),
it is a class name declaration (9.1),
or it is a typedef declaration (7.1.3),
a using-declaration (7.3.3),
or a using-directive (7.3.4)".

So my question is , based on the (7.3.3) line of the clause, why is the
typedef
above a definition?

Because it instantiates a template into a class at that point. The new class
bonds with identifiers seen at its location. Using Point later doesn't
re-bond these identifiers, as #define Point complex<short> would.

This is why one should always instantiate templates with typedefs, to
control their definition point.

--
Phlip
http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces



Back to top
Rob Williscroft
Guest





PostPosted: Sat Jun 26, 2004 7:32 am    Post subject: Re: Declaration or Definition Reply with quote



Phlip wrote in news:dv5Dc.1291$e71.351 (AT) newssvr33 (DOT) news.prodigy.com in
comp.lang.c++:

Quote:
newmans wrote:

Perhaps one of the experts can straighten me out on this point...

In Bjarne Stroustrup's book 'The C++ Programming Language' 3rd
Edition, section 4.9, indicates that

typedef complex<short> Point;

is not only a declaration, but also a definition.

The ISO/IEC 14882:2003(E) standard states in section 3.1 clause 2
that

"A declaration is a definition unless
[...]
or it is a typedef declaration (7.1.3),
[...]
So my question is , based on the (7.3.3) line of the clause, why is
the typedef
above a definition?

The Standard says it isn't, nothing else matters.

Quote:

Because it instantiates a template into a class at that point.

There is no class-template being instantiated here.

Quote:
The new
class bonds with identifiers seen at its location. Using Point later
doesn't re-bond these identifiers, as #define Point complex<short
would.

This is why one should always instantiate templates with typedefs, to
control their definition point.


This was true with some pre-standard version's of C++.

With Standard C++, the problem is /mostly/ mitigated with
2-phase name lookup, if that isn't good enough you can use:

template complex< short >;

But it only works if *all* of complex<>'s member's are
instantiatable with the 'short' argument.

Rob.
--
http://www.victim-prime.dsl.pipex.com/

Back to top
Chris Gordon-Smith
Guest





PostPosted: Sat Jun 26, 2004 4:52 pm    Post subject: Re: Declaration or Definition Reply with quote

newmans wrote:

Quote:
Perhaps one of the experts can straighten me out on this point...

In Bjarne Stroustrup's book 'The C++ Programming Language' 3rd Edition,
section 4.9, indicates that

typedef complex<short> Point;

is not only a declaration, but also a definition.

The ISO/IEC 14882:2003(E) standard states in section 3.1 clause 2 that

"A declaration is a definition unless it declares a function without
specifying the function's body (8.4),
it contains the extern specifier (7.1.1) or a linkage-specification24)
(7.5) and neither an initializer nor a function-body,
it declares a static data member in a class declaration(9.4),
it is a class name declaration (9.1),
or it is a typedef declaration (7.1.3),
a using-declaration (7.3.3),
or a using-directive (7.3.4)".

So my question is , based on the (7.3.3) line of the clause, why is the
typedef
above a definition?

Interesting question. Here is my understanding of the situation.

Section 4.9 of Stroustrup's book says "definitions [...] also define an
entity for the name to which they refer. ... For Point it is the type
complex<short> so that point becoms a synonym for complex<short>".

Therefore, the definition part of this typedef is that it is defining a new
type (the 'entity'), complex<short>.

The type complex<short> would not exist without the typedef.

I assume that the line of the standard you intended to mention was 7.1.3.
This says that a typedef declaration is not a definition. I would think
that an example of this would be

typedef int int32;

This is not defining an 'entity'. In this case, the entity is the built in
type int, which already exists. Therefore this typedef is just declaring
the name int32 as a synonym for the already existing type 'int'.

--
Chris Gordon-Smith
London
Homepage: http://graffiti.virgin.net/c.gordon-smith/
Email Address: Please see my Home Page

Back to top
Alf P. Steinbach
Guest





PostPosted: Sat Jun 26, 2004 6:14 pm    Post subject: Re: Declaration or Definition Reply with quote

* newmans:
Quote:
Perhaps one of the experts can straighten me out on this point...

In Bjarne Stroustrup's book 'The C++ Programming Language' 3rd Edition,
section 4.9, indicates that

typedef complex<short> Point;

is not only a declaration, but also a definition.

The ISO/IEC 14882:2003(E) standard states in section 3.1 clause 2 that

"A declaration is a definition unless it declares a function without
specifying the function's body (8.4),
it contains the extern specifier (7.1.1) or a linkage-specification24) (7.5)
and neither an initializer nor a function-body,
it declares a static data member in a class declaration(9.4),
it is a class name declaration (9.1),
or it is a typedef declaration (7.1.3),
a using-declaration (7.3.3),
or a using-directive (7.3.4)".

So my question is , based on the (7.3.3) line of the clause, why is the
typedef above a definition?

It isn't.

How exactly does Bjarne, in your opinion, "indicate" that it is?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Back to top
Russell Hanneken
Guest





PostPosted: Sat Jun 26, 2004 6:53 pm    Post subject: Re: Declaration or Definition Reply with quote

Alf P. Steinbach wrote:
Quote:
* newmans:

In Bjarne Stroustrup's book 'The C++ Programming Language' 3rd Edition,
section 4.9, indicates that

typedef complex<short> Point;

is not only a declaration, but also a definition.

How exactly does Bjarne, in your opinion, "indicate" that it is?

After giving a list of declarations, including

typedef complex<short> Point;

Stroustrup writes:

Most of these declarations are also definitions, that is, they also
define an entity for the name to which they refer. For ch, that entity
is the appropriate amount of memory to be used as a variable. . . . For
day, it is the specified function. . . . For Point, it is the type
complex<short> so that Point becomes a synonym for complex<short>. Of
the declarations above, only

double sqrt(double);
extern int error_number;
struct User;

are not also definitions; that is, the entity they refer to must be
defined elsewhere.

Seems pretty clear to me. I'm quoting from the 3rd printing of the "special
edition." I checked Stroustrup's errata pages to see if he corrected
himself in a later printing, but I don't see any mention of this issue.

--
Russell Hanneken
[email]eunaarxra (AT) cbobk (DOT) pbz[/email]
Use ROT13 to decode my email address.



Back to top
Russell Hanneken
Guest





PostPosted: Sat Jun 26, 2004 7:01 pm    Post subject: Re: Declaration or Definition Reply with quote

Chris Gordon-Smith wrote:
Quote:
The type complex<short> would not exist without the typedef.

I assume that the line of the standard you intended to mention was 7.1.3.
This says that a typedef declaration is not a definition. I would think
that an example of this would be

typedef int int32;

This is not defining an 'entity'. In this case, the entity is the built in
type int, which already exists. Therefore this typedef is just declaring
the name int32 as a synonym for the already existing type 'int'.

Interesting distinction, but unfortunately the standard says "A declaration
is a definition unless . . . it is a typedef declaration." For your
argument to work, you would have to say that

typedef complex<short> Point;

is a definition, but not a typedef declaration. I don't think the standard
means to say that.

--
Russell Hanneken
[email]eunaarxra (AT) cbobk (DOT) pbz[/email]
Use ROT13 to decode my email address.





Back to top
Alf P. Steinbach
Guest





PostPosted: Sat Jun 26, 2004 7:40 pm    Post subject: Re: Declaration or Definition Reply with quote

* Russell Hanneken:
Quote:
Alf P. Steinbach wrote:
* newmans:

In Bjarne Stroustrup's book 'The C++ Programming Language' 3rd Edition,
section 4.9, indicates that

typedef complex<short> Point;

is not only a declaration, but also a definition.

How exactly does Bjarne, in your opinion, "indicate" that it is?

After giving a list of declarations, including

typedef complex<short> Point;

Stroustrup writes:

Most of these declarations are also definitions, that is, they also
define an entity for the name to which they refer. For ch, that entity
is the appropriate amount of memory to be used as a variable. . . . For
day, it is the specified function. . . . For Point, it is the type
complex<short> so that Point becomes a synonym for complex<short>. Of
the declarations above, only

double sqrt(double);
extern int error_number;
struct User;

are not also definitions; that is, the entity they refer to must be
defined elsewhere.

Seems pretty clear to me. I'm quoting from the 3rd printing of the "special
edition." I checked Stroustrup's errata pages to see if he corrected
himself in a later printing, but I don't see any mention of this issue.

Urm, well.

The only practical difference seems to be that while you cannot have
multiple definitions of the same name (except internal linkage in
different compilation units), you can have multiple typedef's of the
same name provided they denote the same type.

I'm forwarding this to Bjarne, assuming his spam-filter doesn't
automatically trash mails from me... ;-)

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Back to top
Chris Gordon-Smith
Guest





PostPosted: Sat Jun 26, 2004 11:49 pm    Post subject: Re: Declaration or Definition Reply with quote

Russell Hanneken wrote:

Quote:
Chris Gordon-Smith wrote:
The type complex<short> would not exist without the typedef.

I assume that the line of the standard you intended to mention was 7.1.3.
This says that a typedef declaration is not a definition. I would think
that an example of this would be

typedef int int32;

This is not defining an 'entity'. In this case, the entity is the built
in type int, which already exists. Therefore this typedef is just
declaring the name int32 as a synonym for the already existing type
'int'.

Interesting distinction, but unfortunately the standard says "A
declaration
is a definition unless . . . it is a typedef declaration." For your
argument to work, you would have to say that

typedef complex<short> Point;

is a definition, but not a typedef declaration. I don't think the
standard means to say that.


Fair enough. But that does seem to leave us in a rather contradictory
situation:

1) typedef int int32; // Declaration that is not a definition
2) typedef complex<short> Point; // Declaration that is also a
definition (as stated by Stroustrup section 4.9)
3) The standard says "A declaration is a definition unless . . . it is a
typedef declaration."

(2) and (3) can only be consistent if (2) is a declaration (and a
definition), but not a 'typedef declaration'.

Any ideas on a way out of this contradictory situation? What is a 'typedef
declaration'?

--
Chris Gordon-Smith
London
Homepage: http://graffiti.virgin.net/c.gordon-smith/
Email Address: Please see my Home Page

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.