Topic: Forward declarations


Author: kanze@gabi-soft.fr (J. Kanze)
Date: 1996/08/14
Raw View
jason@cygnus.com (Jason Merrill) writes:

> >>>>> James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de> writes:
>
> > In article <199608121825112129542@dialup101-5-16.swipnet.se>
> > lars.farm@nts.mh.se (Lars Farm) writes:
>
> > |> Or could there be "forward typedefs"?
>
> > |>   typedef string;  // to be defined
> > |>   typedef istream;
> > |>   typedef ostream;
>
> > As far as I know, none of what you are proposing is in the draft.
> > However, the last suggestion looks very good to me, except that I would
> > use the new keyword typename: all you are doing is declaring that
> > string, istream, and ostream are (incomplete) types; even if they are
> > defined later as int, this should work.
>
> This would break type-safe linkage, since we must know what 'string' is to
> be able to refer to it by its canonical name.

More exactly put, this would break most current implementations of
typesafe linkage.  More to the point, perhaps: it would require (at
least some) typedef's to have external linkage.

Oh well, it was just an idea...

--
James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils en informatique industrielle --
                            -- Beratung in industrieller Datenverarbeitung
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: lars.farm@nts.mh.se (Lars Farm)
Date: 1996/08/12
Raw View
We used to say:
   class istream;
   class ostream;
We should now say:
   #include <iosfwd>
   ( surrounded by #if ? for years to come ...)

We used to say:
   class string;
What do we say instead?
   #include <string> // give up, #include tons of text everywhere
 or
   template<class charT> struct string_char_traits;
   template<class charT, class traits> class basic_string;
   typedef basic_string<char,string_char_traits<char> > string;
   ( surrounded by #if ? for years to come ...)
 ?

Or could it be that a forward declaration only says that the name
'string' is defined somewere as a class. An ordinary class or a template
class instantation, one way or another? Possibly via typedef?

class C;
class D{};
typedef D C;                  -- ok? if not, why not?

class X;
template<class T> class Y{};
typedef Y<char> X;            -- ok? If not, why not?

Or could there be "forward typedefs"?

  typedef string;  // to be defined
  typedef istream;
  typedef ostream;


--
Lars Farm, lars.farm@nts.mh.se


[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
Date: 1996/08/13
Raw View
In article <199608121825112129542@dialup101-5-16.swipnet.se>
lars.farm@nts.mh.se (Lars Farm) writes:

|> We used to say:
|>    class istream;
|>    class ostream;
|> We should now say:
|>    #include <iosfwd>
|>    ( surrounded by #if ? for years to come ...)

|> We used to say:
|>    class string;
|> What do we say instead?
|>    #include <string> // give up, #include tons of text everywhere
|>  or
|>    template<class charT> struct string_char_traits;
|>    template<class charT, class traits> class basic_string;
|>    typedef basic_string<char,string_char_traits<char> > string;
|>    ( surrounded by #if ? for years to come ...)
|>  ?

|> Or could it be that a forward declaration only says that the name
|> 'string' is defined somewere as a class. An ordinary class or a template
|> class instantation, one way or another? Possibly via typedef?

|> class C;
|> class D{};
|> typedef D C;                  -- ok? if not, why not?

|> class X;
|> template<class T> class Y{};
|> typedef Y<char> X;            -- ok? If not, why not?

|> Or could there be "forward typedefs"?

|>   typedef string;  // to be defined
|>   typedef istream;
|>   typedef ostream;

As far as I know, none of what you are proposing is in the draft.
However, the last suggestion looks very good to me, except that I would
use the new keyword typename: all you are doing is declaring that
string, istream, and ostream are (incomplete) types; even if they are
defined later as int, this should work.

This is, in fact, legal in templates, so it shouldn't be too difficult
to extend it to be legal outside of templates.
--
James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils, itudes et rialisations en logiciel orienti objet --
                -- A la recherche d'une activiti dans une region francophone
---
[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: jason@cygnus.com (Jason Merrill)
Date: 1996/08/13
Raw View
>>>>> James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de> writes:

> In article <199608121825112129542@dialup101-5-16.swipnet.se>
> lars.farm@nts.mh.se (Lars Farm) writes:

> |> Or could there be "forward typedefs"?

> |>   typedef string;  // to be defined
> |>   typedef istream;
> |>   typedef ostream;

> As far as I know, none of what you are proposing is in the draft.
> However, the last suggestion looks very good to me, except that I would
> use the new keyword typename: all you are doing is declaring that
> string, istream, and ostream are (incomplete) types; even if they are
> defined later as int, this should work.

This would break type-safe linkage, since we must know what 'string' is to
be able to refer to it by its canonical name.

f1.C:

typename string;

void foo (string *) { }

f2.C:

#include <string>

extern void foo (string *);

Are these declarations compatible?

Jason


[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]