[Freeciv-Dev] Re: [FreeCiv-Cvs] vasc: Added cast to placate g++.
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Tue, Feb 12, 2002 at 08:27:31PM +0000, Vasco Alexandre Da Silva Costa wrote:
> On Tue, 12 Feb 2002, Raimar Falke wrote:
>
> > You made a lot of changes like this:
> >
> > diff -X real_clean/diff_ignore -urd real_clean/common/astring.c
> > freeciv.clean/common/astring.c
> > --- real_clean/common/astring.c Sun Feb 10 22:36:42 2002
> > +++ freeciv.clean/common/astring.c Tue Feb 12 09:04:04 2002
> > @@ -76,7 +76,7 @@
> > /* allocated more if this is only a small increase on before: */
> > n1 = (3*(astr->n_alloc+10)) / 2;
> > astr->n_alloc = (n > n1) ? n : n1;
> > - astr->str = fc_realloc(astr->str, astr->n_alloc);
> > + astr->str = (char *)fc_realloc(astr->str, astr->n_alloc);
> > }
> >
> > These are bad changes IMHO. Casting the return type of malloc is
> > unnecessary for plain C and it can mask errors like you forgot to
> > include "stdlib.h" (or "mem.h").
> >
> > In short: freeciv is C and not C++ (were such casts are required).
>
> Well, IIRC some parts of the code already added the casts.
A quick grep shows:
./client/clinet.c: struct server *pserver = (struct
server*)fc_malloc(sizeof(struct server));
plus stuff in amiga/, intl/ and client/gui-mui/. So this is only one
"real hit".
> So IMHO its not that bad to add them in this case.
> Some other warnings by g++ were valid even for C code, like
> intermixing enums and ints in strange ways, and missing
> includes. And extra -W flags can trap those include errors you
> mention.
I have no problems with such if there were real errors in the C
domain.
> Besides this, i think we should aim to make freeciv compileable with
> a C++ compiler, just to keep our options open.
IMHO this isn't this useful because it is a huge difference between
"compiles with a C++ compiler" and "is a C++ program". You can achieve
the latter either by gradual replacing of constructs (like ObjectCiv
has done, and died shortly afterwards after a "s/struct/class/" patch)
or a rewrite from scratch. If I would like to make a C++ version of
freeciv (this isn't my goal) I would do it from scratch. With a
reasonable understanding of the problem domain you can get a good OO
design.
> K&R 2nd edition is a C book, and nonetheless all code contained
> therein is valid C++.
I don't have the book but I would careful with such a statement. A
variable named "new" or "bool" is enough.
> Of course, if people don't like the casts that much, i can remove them
> again.
Comments?
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
Living on earth may be expensive, but it includes an annual free trip
around the sun.
|
|