public inbox for cygwin-talk@cygwin.com
 help / color / mirror / Atom feed
From: Igor Peshansky <pechtcha@cs.nyu.edu>
To: The Cygwin-Talk Maiming List <cygwin-talk@cygwin.com>
Subject: RE: how come #include "*.cpp" works?
Date: Wed, 24 May 2006 17:28:00 -0000	[thread overview]
Message-ID: <Pine.GSO.4.63.0605241321440.19906@access1.cims.nyu.edu> (raw)
In-Reply-To: <052701c67f55$89e7b7d0$a501a8c0@CAM.ARTIMI.COM>

On Wed, 24 May 2006, Dave Korn wrote:

> On 24 May 2006 17:00, mwoehlke wrote:
>
> > === For declaring an object
> > #define CREATABLE_CLASS(name) \
> > extern class OBJECT* create_##name( int argc, const char* argv[] ); \
> > class name : virtual public OBJECT
>
> > === So main.cpp doesn't need the headers for every class
> > #undef CREATABLE_CLASS
> > #define CREATABLE_CLASS(name) \
> > extern class T_OBJ* create_##name( int argc, const char* argv[] );
> > #include "objects.def"
>
>   Bad idea, I think.  You now have two separate bits of code that are
> generating the prototypes for this set of functions.  You run the danger
> of getting inconsistent code.  In this case, unless T_OBJ is the exact
> same type as OBJECT, you've already made (technically speaking)
> undefined behaviour, haven't you?  Umm, perhaps I mean "Would someone
> remined me whether C++ mangled names include the return type, or just
> the args signature?"

The mangled name doesn't, but C++ will invoke different coercions based
on the return type, so if OBJECT and T_OBJ are indeed different types,
calling the function in exactly the same way from main.cpp and another
file may result in completely different behavior.

>   Perhaps it would be better to factor out the prototype generation into
> a separate macro that could be invoked by both instances of "#define
> CREATABLE_CLASS" ?

What's wrong with the following?

#define _CREATABLE_CLASS_DECL(name) \
class name : virtual public OBJECT
#define _CREATABLE_CLASS_PROTO(name) \
extern class OBJECT* create_##name( int argc, const char* argv[] );

#ifndef CC_NO_CLASS_DECL
#define CREATABLE_CLASS(name) \
_CREATABLE_CLASS_PROTO(name) \
_CREATABLE_CLASS_DECL(name)
#else
#define CREATABLE_CLASS(name) \
_CREATABLE_CLASS_PROTO(name)
#endif

and then, in main.cpp:

#define CC_NO_CLASS_DECL
#include "objects.def"

	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_	    pechtcha@cs.nyu.edu | igor@watson.ibm.com
ZZZzz /,`.-'`'    -.  ;-;;,_		Igor Peshansky, Ph.D. (name changed!)
     |,4-  ) )-,_. ,\ (  `'-'		old name: Igor Pechtchanski
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Las! je suis sot... -Mais non, tu ne l'es pas, puisque tu t'en rends compte."
"But no -- you are no fool; you call yourself a fool, there's proof enough in
that!" -- Rostand, "Cyrano de Bergerac"

  reply	other threads:[~2006-05-24 17:28 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <44638BED.5020009@telenet.be>
     [not found] ` <4463A0D4.1060006@cygwin.com>
2006-05-17 15:52   ` mwoehlke
2006-05-17 16:00     ` Dave Korn
2006-05-17 16:28       ` Igor Peshansky
2006-05-17 16:57         ` Dave Korn
2006-05-18 14:46       ` mwoehlke
2006-05-18 16:59         ` Jason Alonso
2006-05-18 17:24         ` Dave Korn
2006-05-18 18:28           ` mwoehlke
2006-05-18 18:31             ` Dave Korn
2006-05-18 19:10               ` mwoehlke
2006-05-24 16:03         ` mwoehlke
2006-05-24 17:14           ` Dave Korn
2006-05-24 17:28             ` Igor Peshansky [this message]
2006-05-24 17:51               ` Dave Korn
2006-05-24 18:36               ` mwoehlke
2006-05-24 18:17             ` mwoehlke
2006-05-17 17:01     ` Dave Korn

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=Pine.GSO.4.63.0605241321440.19906@access1.cims.nyu.edu \
    --to=pechtcha@cs.nyu.edu \
    --cc=cygwin-talk@cygwin.com \
    /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).