<URL: http://bugs.freeciv.org/Ticket/Display.html?id=21625 >

> [vasc - Thu Oct 05 22:44:29 2006]:
> 
> Freeciv uses some C99 features. C99 has integer types which are 
guaranteed
> to fit pointer values:
> intptr_t and uintptr_t from inttypes.h.

I did not know that. The question is can I assume that these C99
features will exist everywhere freeciv is expected to compile?

> 
> This is the ugliest bit I found:
> ---
> +#undef get16bits
> +#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) 
\
> +  || defined(_MSC_VER) || defined (__BORLANDC__) || defined 
(__TURBOC__)
> +#define get16bits(d) (*((const uint16_t *) (d)))
> +#endif
> +
> +#if !defined (get16bits)
> +#define get16bits(d) ((((const uint8_t *)(d))[1] << UINT32_C(8))\
> +                      +((const uint8_t *)(d))[0])
> +#endif
> ---
> 
> Basically the first case caters for a little-endian X86 architecture. 
I am
> somewhat unsure what this
> macro is supposed to do, but my guess is it is meant to snarf 16-bits 
in
> little endian order.
> 
> I think the second case would work on a big-endian architecture. This 
sort
> of #ifdef'ing is against
> autoconf style. The check should IMO be for endianness not any 
specific
> compiler. Alternatively,
> forget the little tin god and just use the, more generic, second macro
> definition.

I agree completely. The only reason this code snippet
survived as long as it did is because it was in the
original SuperFastHash (which tried to be as self contained
as possible and so didn't use autoconf style macros)
and did not generate any compile warnings or errors.
I'm sure we can spare the few extra cycles to use only
the more generic version. :)

Attachment: freeciv_S2_1_r12321-004-intptr_t_for_ptr_conversion_macros.diff
Description: Binary data

Attachment: freeciv_S2_1_r12321-004-super_fast_hash_sanitization.diff
Description: Binary data

_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to