🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: chile.comp.programacion
Article #2368

Re: Portar codigo C entre maquinas de 32/64 bits?

#2368
From: Waldo
Date: Tue, 13 Dec 2005 17:27
44 lines
2390 bytes
Andres E. Hernando wrote:

[...]
> 	Estoy seguro que debe haber una forma de asegurarme
> que y es siempre de 32 bits independiente de la arquitectura,
> pero hace como 4 annos que no programo en C... Algun puntero
> a la ayuda adecuada?

[una respuesta algo mas general que la deseada, sin mirar el codigo de
prng]

Si no te importa usar cosas de C99, #incluye <stdint.h> y declara "y"
como uint32_t.

Si quieres permanecer en C89 o en K&R, tienes mas trabajo por delante.
Si no usas autoconf ni nada parecido, pon un typedef apropiado en
alguna parte y en un README indicas que cambiar y donde para ajustar tu
codigo a otra plataforma.

Si usas autoconf, agrega a `configure.ac' lineas por el estilo de

AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(long)

y en alguna otra parte usa los resultados para definir tu analogo de
uint32_t:

#include "config.h"

#if SIZEOF_INT == 4
  typedef unsigned int my_uint32_t;
#elif SIZEOF_SHORT == 4
  typedef unsigned short int my_uint32_t;
#elif SIZEOF_LONG == 4
  typedef unsigned long my_uint32_t;
#else
#  error No hay tipo numerico de 32 bits!
#endif

Con eso puedes declarar "y" como my_uint32_t.

Salu2,
W.
Technical Details
Message-ID: <1134494841.356315.244970@g43g2000cwa.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g43g2000cwa.googlegroups.com!not-for-mail
References: <40656sF18epvjU1@individual.net>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,88c16e828b86c7df
X-Google-Attributes: gid1593cb,public
X-Google-Language: SPANISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g43g2000cwa.googlegroups.com!not-for-mail
From: "Waldo" <fatwaldo@yahoo.com>
Newsgroups: chile.comp.programacion
Subject: Re: Portar codigo C entre maquinas de 32/64 bits?
Date: 13 Dec 2005 09:27:21 -0800
Organization: http://groups.google.com
Lines: 45
Message-ID: <1134494841.356315.244970@g43g2000cwa.googlegroups.com>
References: <40656sF18epvjU1@individual.net>
NNTP-Posting-Host: 167.206.68.10
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1134494849 12265 127.0.0.1 (13 Dec 2005 17:27:29 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 13 Dec 2005 17:27:29 +0000 (UTC)
In-Reply-To: <40656sF18epvjU1@individual.net>
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8) Gecko/20051111 Firefox/1.5,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: g43g2000cwa.googlegroups.com; posting-host=167.206.68.10;
   posting-account=hVjo8QwAAAC1br25yrexfun-OkEnsf06