On Dec 12, 2007 9:31 PM, Ivan Vucica <[EMAIL PROTECTED]> wrote:
> On Dec 12, 2007 6:27 PM, Nuno Lucas <[EMAIL PROTECTED]> wrote:
[...]
> > > uint16_t getu16(char **p) {
> > >     uint16_t a = **p + (*(*p+1) << 8); // please ignore endianess
> > >     *p +=2;
> > >     return a;
> > > }
> >
> > I wouldn't trust the return value here, but you seem to not be using it, 
> > so...
>
> This isn't the actual code, just an approximation, and we do use it.
> It can be e.g. amount of HP lost by the player.

Explaining a bit more what I had mean, you are doing an 8-bit shift on
a char. Some compilers will first convert the value to int and then do
the shift, while others will apply the shift to the 8-bit value
(meaning the result will always be 0).

I don't know what the C standard says about this, but as I have been
bitten by this before I always use proper casts to avoid any problems
on the day I decide to copy/paste some old code.

It's possible you will have no problems with this code, though (maybe
recent compilers all do the right thing now).


Regards,
~Nuno Lucas

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Cegcc-devel mailing list
Cegcc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cegcc-devel

Reply via email to