[airstrike] [Fwd: Re: Bug in mech.c]
ulfek at ifm.liu.se
Tue Jun 1 09:16:22 EDT 2004
> At this moment I do not have MS Visual Studio installed, so I cant make
> changes in the source code for this moment. This problem will be solved I
> a couple of days
Ok. Some comments though:
> 1) Problem in: engine/levels.c and engine/msg_types.h
> Some cast problems depending on MS compiler, fixex by Eero. I will look at
> them when I have MS Studio installed.
These casts (casting a void * pointer to some other pointer) are not
needed and should not be used in C. You are probably trying to use a
C++ compiler or an old compiler.
Read http://www.eskimo.com/~scs/cclass/int/sx4bb.html for the full story,
"Once upon a time, before the void * type had been invented, malloc
returned a char *, which had to be converted to the type you were
using. For example, one used to write things like
int *iarray = (int *)malloc(100 * sizeof(int));
struct list *lp = (struct list *)malloc(sizeof(struct list));
These casts are not necessary under an ANSI C compiler (because malloc
returns void * which the compiler converts automatically), but you may
still see them in older code."
Obviously we are not writing older code.
> 2) Changes in: sprites/bonus.c, sprites/draco.c, sprites/zeppelin.c
> I changed '|=' and '&=' in '=', I do not understand where difficult to
> understand construction like |= and &= are necessary in the source code of
> this sprites. I know what the mean but it seems to me that they are not
> necessary. I replaced them and tested them to see of there where different
> results, but I any case the results are the same (equal or one).
The intent of the flags member of the sprite struct is to hold
different kinds of binary flags for each sprite. This means that we
can hold 32 flags (we require at least 32 bit int's). If you replace
|= with = you clear all the other bits, which is not what we want. If
you for some reason want to avoid the usage of the |= operator you
should tranform x |= y to x = x | y, but we consider this to be bad
style in Airstrike.
The real problem is that sprite.flags is an enum, we should change it
to an unsigned int, although the present usage is valid C.
> I dont think its necessary to place them back.
> Eero did also added some OS specific ifdefs, I will look at the later.
I put a new file for all the OS specific code: src/core/compat.h You
can add a src/core/compat.c if you need it for some reason. It would
be nice if all platform specific code is in this file, although it may
not be possible in all cases.
More information about the airstrike