public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: corey taylor <corey.taylor@gmail.com>
To: Kristian Kratzenstein <kristian.kratzenstein@kielnet.net>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Problem with class operators.
Date: Mon, 25 Jul 2005 19:07:00 -0000	[thread overview]
Message-ID: <2e393d0805072512066a321cac@mail.gmail.com> (raw)
In-Reply-To: <fc.0000000100014e853b9aca0075893219.14e86@KielNet.net>

I don't know.  I always put my templated definitions in the header
file. MSVC++ usually errors on other uses also, I'm surprised these
work.

corey

On 7/25/05, Kristian Kratzenstein <kristian.kratzenstein@kielnet.net> wrote:
> Corey, Eljay,
> 
> This kind works also with gcc, but not with small methods (CW and VC could
> handle small methods too).
> 
> meanwhile : I declare the class fully
> 
> template<class T>
> class x
> {
> public:
>         x();
>         ~x();
> ....
> }
> 
> before using them, so I'm allowed to use x<char> ch.
> 
> But the methods are defined in the cpp file. And now came the compiler /
> linker problem.
> bigger methods (4 lines or more) are fine. Gcc compile them, and I could
> link to them also from other files, cause gcc doesn't use any kind of
> inline to optimize them away. They are preserved. But smaller are gone,
> gcc put them into the code (inline). So I could not link to them.
> 
> What is now my conclusion : put small methods into the class decleration.
> But this looks dirty (sorry, but I try to hold my code clean). Is no other
> way, to stop gcc to inline small methods ?
> 
> thanks,
> 
> Kristian
> 
> corey taylor <corey.taylor@gmail.com> on Montag, 25. Juli 2005 at 20:13
> +0100 wrote:
> >Kristian,
> >
> >  Are you asking if there is a way for the compiler to make note of an
> >internal linkage and instantiation in one file and translate that to
> >another file?
> >
> >  I think that you'll find scoping rules will limit this.  The
> >declaration and sometimes definition needs to be visible at the time
> >of instantiation.
> >
> >  A basic example is section 14.7 paragraph 6 of the specification:
> >
> >If an implicit instantiation of a class template specialization is
> >required and the template is declared but not
> >defined, the program is ill-formed.
> >
> >[Example:
> >template<class T> class X;
> >
> >X<char> ch; // error: definition of X required
> >—end example]
> >
> >Paragraph 3 gives examples for required method instantiations.
> >
> >corey
> >
> >On 7/25/05, Kristian Kratzenstein <kristian.kratzenstein@kielnet.net>
> >wrote:
> >> Hi Eljay,
> >>
> >> Nearly as I thought. But : When the template method / function is used
> >in
> >> the related cpp file, then the Linker could link from other files to the
> >> same function (with same type).
> >> Therefor I use a dummyfunction.
> >>
> >> The problem now is, that CW and VC preserve the methods during
> >compiling.
> >> gcc now optimize them away (small, like GetBuffer or so), so they run in
> >> the file, but cannot be linked.
> >>
> >> So, is there a way to get those methods preserved, so I could link to
> >them
> >> ?
> >>
> >> I know, the best is : into the Headers. But I made template classes
> >> (some), which are based on each other. Cause the size, I would like to
> >> have them in cpp / h file. Also this looks more clean.
> >>
> >> Kind regards
> >>
> >> Eljay Love-Jensen <eljay@adobe.com> on Montag, 25. Juli 2005 at 17:32
> >> +0100 wrote:
> >> >Hi Kristian,
> >> >
> >> >Non-specialized template functions and methods need to be defined in
> >the
> >> >header file which declares them.
> >> >
> >> >Otherwise they are only visible to the translation unit in which they
> >are
> >> >defined.
> >> >
> >> >HTH,
> >> >--Eljay
> >> >
> >> >
> >> >
> >>
> >>
> >>
> >> --------------------------------------------
> >> Kristian Kratzenstein
> >> Gettorf
> >>
> >> Kristian.Kratzenstein@KielNET.net
> >> --------------------------------------------
> >>
> >>
> >>
> >>
> 
> 
> --------------------------------------------
> Kristian Kratzenstein
> Gettorf
> 
> Kristian.Kratzenstein@KielNET.net
> --------------------------------------------
> 
> 
>

  reply	other threads:[~2005-07-25 19:07 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-25  7:50 Which ELF platforms support visibility attribute? Jonathan Turkanis
2005-07-25  8:26 ` Problem with class operators Kristian Kratzenstein
2005-07-25 11:44   ` Eljay Love-Jensen
2005-07-25 12:06     ` Kristian Kratzenstein
2005-07-25 15:17     ` Kristian Kratzenstein
2005-07-25 15:32       ` Eljay Love-Jensen
2005-07-25 17:47         ` Kristian Kratzenstein
2005-07-25 18:00           ` Eljay Love-Jensen
2005-07-25 18:13           ` corey taylor
2005-07-25 19:02             ` Kristian Kratzenstein
2005-07-25 19:07               ` corey taylor [this message]
2005-07-25 19:32               ` Eljay Love-Jensen
2005-07-25 15:49       ` corey taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2e393d0805072512066a321cac@mail.gmail.com \
    --to=corey.taylor@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=kristian.kratzenstein@kielnet.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).