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

Freeciv uses some C99 features. C99 has integer types which are guaranteed
to fit pointer values:
intptr_t and uintptr_t from inttypes.h. Although from a first glace at the
code this does not seem to be a problem.

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.

On 10/5/06, book <[EMAIL PROTECTED]> wrote:
>
>
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=21625 >
>
>
>
> ----- Original Message Follows -----
> From: "Per I. Mathisen" <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: Re: [Freeciv-Dev] (PR#21625) PATCH - improved hash
> tables
> Date: Wed, 4 Oct 2006 12:01:18 -0700
>
> > Are those pointer conversion macros 64bit safe? For all
> > types of common  64bit systems?
>
> No idea. As I don't have a 64bit system to test, never
> programmed on one, and
> only made the conversion macros by monkeying glib :).
>
> Actually a better way to construct the macros would be to
> have sizeof check for
> pointers in configure.ac and then use AC_DEFINE (or
> whatever) to substitute in
> the correct cast expression (this is the way glib actually
> does it, I got lazy).
>
>
>
>
> _______________________________________________
> Freeciv-dev mailing list
> Freeciv-dev@gna.org
> https://mail.gna.org/listinfo/freeciv-dev
>



-- 
Vasco Alexandre da Silva Costa

Freeciv uses some C99 features. C99 has integer types which are guaranteed to fit pointer values:
intptr_t and uintptr_t from inttypes.h. Although from a first glace at the code this does not seem to be a problem.

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.

On 10/5/06, book <[EMAIL PROTECTED]> wrote:

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



----- Original Message Follows -----
From: "Per I. Mathisen" < [EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: Re: [Freeciv-Dev] (PR#21625) PATCH - improved hash
tables
Date: Wed, 4 Oct 2006 12:01:18 -0700

> Are those pointer conversion macros 64bit safe? For all
> types of common  64bit systems?

No idea. As I don't have a 64bit system to test, never
programmed on one, and
only made the conversion macros by monkeying glib :).

Actually a better way to construct the macros would be to
have sizeof check for
pointers in configure.ac and then use AC_DEFINE (or
whatever) to substitute in
the correct cast _expression_ (this is the way glib actually
does it, I got lazy).




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



--
Vasco Alexandre da Silva Costa
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to