Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] Re: (PR#11213) Making client headers compatible with C++
Home

[Freeciv-Dev] Re: (PR#11213) Making client headers compatible with C++

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#11213) Making client headers compatible with C++
From: "Frédéric Brière" <fbriere@xxxxxxxxxxx>
Date: Fri, 3 Dec 2004 13:24:52 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=11213 >

On Wed, Dec 01, 2004 at 10:53:05AM -0800, Jason Short wrote:
> But, we should first make a patch for doc/HACKING that states the policy 
> on C++ compatibility.  Can you write something up and put it under this 
> ticket?

I'm not sure what you want me to write.  I'm not sure you even *need*
such a policy.  Making the headers C++-compatible should be a one-time
job, not a journey that you need to embark on each time somebody comes
forward with a new client.  The tickets I've filed take care of all the
issues I'm aware of.  When they're all resolved, one should be able to
drop in a C++ with only minimal changes to configure.ac and
client/Makefile.am.

Still, if I had to dispense some words of wisdom, I would offer the
following advice:


* To anybody about to work on a C++ client:

Since all Freeciv core and client headers are intended to be compatible
with C++, you should be able to copy all of gui-stub, wrap the #includes
within extern "C", and start from there.

Your autoconf macro in m4/ should AC_REQUIRE([AC_HEADER_STDBOOL]), and
fail if $ac_cv_header_stdbool_h != yes.  This should help ensure that
the C core and C++ client agree on the size of bool.  (It's not a
guarantee, though.)

C++-specific flags should go into CLIENT_CXXFLAGS; add the following
line to your Makefile.am:

  AM_CXXFLAGS =  @CLIENT_CXXFLAGS@

Remember to add -lm and/or -lstdc++ to CLIENT_LIBS if you're not already
linking to a library that will pull them in.


* To anybody failing to compile/link a C++ client:

If you get an error when compilink/linking a C++ client, make sure you
understand *what* is going wrong before you act.  David Tribble's list
of incompatibilities between C and C++ [*] is a useful reference, and
you can also seek advice on comp.std.c and comp.std.c++.  Maybe you've
actually found a violation of the C language, in which case you can kill
two birds with one stone.

 [*] http://david.tribble.com/text/cdiffs.htm

If the problem indeed stems from an imcompatibility between C and C++,
you should open a ticket that includes an explanation of the
incompatibility and a patch that corrects it, if possible.  It's best to
try and make the whole source compatible with both languages, instead of
sprinkling __cplusplus exceptions all over the place.  Nevertheless,
there may be cases where a strategic #ifdef might be preferable to
massive changes.  If in doubt, ask the Freeciv developers.


* To anybody working on the Freeciv core:

If you know C++, try to avoid introducing changes that you know would
cause problems for C++ clients.  (David Tribble's list may help refresh
your memory on some points.)  If you don't know C++, you should at the
very least avoid using any C++ reserved keyword [*] in your headers.

 [*] http://david.tribble.com/text/cdiffs.htm#C99-cpp-keyword

Although it's not a panacea, it might help to try compiling your work
with -pedantic -ansi or -pedantic -std=c99, to help spot any violation
of C89/C99.


-- 
             Frédéric Brière    <*>    fbriere@xxxxxxxxxxx

 =>  <fbriere@xxxxxxxxxx> IS NO MORE:  <http://www.abacomsucks.com>  <=





[Prev in Thread] Current Thread [Next in Thread]