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 

templates & obj

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





PostPosted: Sat Sep 27, 2003 6:51 pm    Post subject: templates & obj Reply with quote



When you compile a cpp program that includes a template class in a .h file
where does the compiled code go for that templated class? If it went in the
obj for the cpp program seems to me you could end up with multiple templates
of the same type if the .h file was included in multiple .cpp. Seems more
straight forward that it would be put in a obj for the .h and the compiler
would just add new ones to the obj for template types that had not been
created by other cpp.

Or if it was included in every cpp obj then I guess it would have a flag in
the obj for to ignore duplicates of the same template type.

Just curious how it worked.


Back to top
Victor Bazarov
Guest





PostPosted: Sat Sep 27, 2003 7:36 pm    Post subject: Re: templates & obj Reply with quote



"Steven C." <nospam (AT) xxx (DOT) com> wrote...
Quote:
When you compile a cpp program that includes a template class in a .h file
where does the compiled code go for that templated class?

Somewhere in the same obj file.

Quote:
If it went in the
obj for the cpp program seems to me you could end up with multiple
templates
of the same type if the .h file was included in multiple .cpp.

Yes, and the linker is supposed to eliminate the multiplicity.

Quote:
Seems more
straight forward that it would be put in a obj for the .h and the compiler
would just add new ones to the obj for template types that had not been
created by other cpp.

While creating one obj file, the compiler knows nothing about other
obj files that have been or will be created.

Quote:
Or if it was included in every cpp obj then I guess it would have a flag
in
the obj for to ignore duplicates of the same template type.

It's all in the function signatures, I guess.

Quote:
Just curious how it worked.

You're lucky to have time to be curious about those things.

Victor




Back to top
Steven C.
Guest





PostPosted: Sat Sep 27, 2003 8:20 pm    Post subject: Re: templates & obj Reply with quote



"Victor Bazarov" <v.Abazarov (AT) attAbi (DOT) com> wrote in
Quote:
When you compile a cpp program that includes a template class in a .h file
where does the compiled code go for that templated class?

Somewhere in the same obj file.

Quote:
If it went in the
obj for the cpp program seems to me you could end up with multiple
templates
of the same type if the .h file was included in multiple .cpp.

Yes, and the linker is supposed to eliminate the multiplicity.

Quote:
Seems more
straight forward that it would be put in a obj for the .h and the compiler
would just add new ones to the obj for template types that had not been
created by other cpp.

While creating one obj file, the compiler knows nothing about other
obj files that have been or will be created.

Quote:
Or if it was included in every cpp obj then I guess it would have a flag
in
the obj for to ignore duplicates of the same template type.

It's all in the function signatures, I guess.
___________________________________________________________

Seem sorta stupid that the compiler is compiling the same code over and over
again, assuming of course the the h file is included in multiple .cpp and
all the cpp require the same types.



Back to top
Mike Wahler
Guest





PostPosted: Sat Sep 27, 2003 9:20 pm    Post subject: Re: templates & obj Reply with quote


"Steven C." <nospam (AT) xxx (DOT) com> wrote

Quote:
"Victor Bazarov" <v.Abazarov (AT) attAbi (DOT) com> wrote in
When you compile a cpp program that includes a template class in a .h
file
where does the compiled code go for that templated class?

Somewhere in the same obj file.

If it went in the
obj for the cpp program seems to me you could end up with multiple
templates
of the same type if the .h file was included in multiple .cpp.

Yes, and the linker is supposed to eliminate the multiplicity.

Seems more
straight forward that it would be put in a obj for the .h and the
compiler
would just add new ones to the obj for template types that had not been
created by other cpp.

While creating one obj file, the compiler knows nothing about other
obj files that have been or will be created.

Or if it was included in every cpp obj then I guess it would have a flag
in
the obj for to ignore duplicates of the same template type.

It's all in the function signatures, I guess.
___________________________________________________________

Seem sorta stupid that the compiler is compiling the same code over and
over
again,

It will compile what you tell it to, as
many times as you tell it.

Quote:
assuming of course the the h file is included in multiple .cpp and
all the cpp require the same types.

Read again what Victor wrote:
"While creating one obj file, the compiler knows nothing about other
obj files that have been or will be created."

The contents of any #included headers become part of the
text of the file which #includes them. This combination
is known as a 'translation unit', which the compiler
translates into an 'object file'. The compiler cannot
know what the contents of other files are, they're
not input to the compile.

-Mike



Back to top
Steven C.
Guest





PostPosted: Sat Sep 27, 2003 11:00 pm    Post subject: Re: templates & obj Reply with quote


"Mike Wahler" <mkwahler (AT) mkwahler (DOT) net>

"Steven C." <nospam (AT) xxx (DOT) com> wrote

Quote:
"Victor Bazarov" <v.Abazarov (AT) attAbi (DOT) com> wrote in
When you compile a cpp program that includes a template class in a .h
file
where does the compiled code go for that templated class?

Somewhere in the same obj file.

If it went in the
obj for the cpp program seems to me you could end up with multiple
templates
of the same type if the .h file was included in multiple .cpp.

Yes, and the linker is supposed to eliminate the multiplicity.

Seems more
straight forward that it would be put in a obj for the .h and the
compiler
would just add new ones to the obj for template types that had not been
created by other cpp.

While creating one obj file, the compiler knows nothing about other
obj files that have been or will be created.

Or if it was included in every cpp obj then I guess it would have a flag
in
the obj for to ignore duplicates of the same template type.

It's all in the function signatures, I guess.
___________________________________________________________

Seem sorta stupid that the compiler is compiling the same code over and
over
again,

It will compile what you tell it to, as
many times as you tell it.

Quote:
assuming of course the the h file is included in multiple .cpp and
all the cpp require the same types.

Read again what Victor wrote:
"While creating one obj file, the compiler knows nothing about other
obj files that have been or will be created."

The contents of any #included headers become part of the
text of the file which #includes them. This combination
is known as a 'translation unit', which the compiler
translates into an 'object file'. The compiler cannot
know what the contents of other files are, they're
not input to the compile.

-Mike

___________________________________________________________

Mike,

Either you are being argumentative or misunderstood my response to Victor.

I'm sure with a little imagination and thought you could see how compilers
could be smarter about how they managed and compiled templates.

Have a good day. :-)





Back to top
Mike Wahler
Guest





PostPosted: Sun Sep 28, 2003 1:33 am    Post subject: Re: templates & obj Reply with quote

"Steven C." <nospam (AT) xxx (DOT) com> wrote

Quote:

"Mike Wahler" <mkwahler (AT) mkwahler (DOT) net

"Steven C." news:pimdb.9521$Ak3.4846 (AT) twister (DOT) socal.rr.com...
"Victor Bazarov" <v.Abazarov (AT) attAbi (DOT) com> wrote in
When you compile a cpp program that includes a template class in a .h
file
where does the compiled code go for that templated class?

Somewhere in the same obj file.

If it went in the
obj for the cpp program seems to me you could end up with multiple
templates
of the same type if the .h file was included in multiple .cpp.

Yes, and the linker is supposed to eliminate the multiplicity.

Seems more
straight forward that it would be put in a obj for the .h and the
compiler
would just add new ones to the obj for template types that had not
been
created by other cpp.

While creating one obj file, the compiler knows nothing about other
obj files that have been or will be created.

Or if it was included in every cpp obj then I guess it would have a
flag
in
the obj for to ignore duplicates of the same template type.

It's all in the function signatures, I guess.
___________________________________________________________

Seem sorta stupid that the compiler is compiling the same code over and
over
again,

It will compile what you tell it to, as
many times as you tell it.

assuming of course the the h file is included in multiple .cpp and
all the cpp require the same types.

Read again what Victor wrote:
"While creating one obj file, the compiler knows nothing about other
obj files that have been or will be created."

The contents of any #included headers become part of the
text of the file which #includes them. This combination
is known as a 'translation unit', which the compiler
translates into an 'object file'. The compiler cannot
know what the contents of other files are, they're
not input to the compile.

-Mike

___________________________________________________________

Mike,

Either you are being argumentative

Not at all.

Quote:
or misunderstood my response to Victor.

Perhaps. Feel free to clarify.


Quote:

I'm sure with a little imagination and thought you could see how compilers
could be smarter about how they managed and compiled templates.

What compilers *could* be or do doesn't matter. It's
the language definition that does. And what is it
about template handling that you find not 'smart'
enough?

-Mike

Quote:

Have a good day. Smile

I will, thanks. :-)

-Mike



Back to top
David Rubin
Guest





PostPosted: Mon Sep 29, 2003 3:50 pm    Post subject: Re: templates & obj Reply with quote

Victor Bazarov wrote:
Quote:

"Steven C." <nospam (AT) xxx (DOT) com> wrote...
When you compile a cpp program that includes a template class in a .h file
where does the compiled code go for that templated class?

Somewhere in the same obj file.

If it went in the
obj for the cpp program seems to me you could end up with multiple
templates
of the same type if the .h file was included in multiple .cpp.

Yes, and the linker is supposed to eliminate the multiplicity.

How does this work if you are linking to an object file which is
compiled with a different compiler than yours? I am under the impression
that there is no standard for naming (i.e., mangled names) in object
files.

/david

--
Andre, a simple peasant, had only one thing on his mind as he crept
along the East wall: 'Andre, creep... Andre, creep... Andre, creep.'
-- unknown

Back to top
Victor Bazarov
Guest





PostPosted: Mon Sep 29, 2003 5:22 pm    Post subject: Re: templates & obj Reply with quote

"David Rubin" <bogus_address (AT) nomail (DOT) com> wrote...
Quote:
[..]
How does this work if you are linking to an object file which is
compiled with a different compiler than yours? I am under the impression
that there is no standard for naming (i.e., mangled names) in object
files.

You are correct. And it is not supposed to work. C++ language
standard ensures only source-level compatibility between compilers.

Victor



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.