🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #5815

Re: tamaño en bytes

#5815
From: J.A. Gutierrez
Date: Tue, 09 Sep 2003 06:41
445 lines
11399 bytes
Raul de la Cruz <user@example.net> wrote:


: Claramente los tama�os de las variables se mantienen en todas las 
: distribuciones de GNU/Linux siempre y cuando se compilen usando el mismo 
: compilador, en este caso el gcc.

	y con los mismos flags, la misma version, sobre la misma
	arquitectura, etc etc.

: As� pues podemos decir que el tama�o en memoria de dichas variables 
: depende siempre del compilador utilizado y de la arquitectura del 
: procesador.

	y de los flags (-mint64, -mlong32, -m128bit-long-double etc)


: Por otro lado lo m�s probable es que si tuvieras una CPU de 64 bits y 
: compilaras con gcc te saldria long: 8 (64 bits) y los punteros otros 8 
: bytes (64 bits) para poder direccionar los 2^64 bytes de memoria posibles.

This is a 64 bits architecture
size of D_WORD is 4 (should be 4)
__STDC__        defined (ANSI C compiler)
LANGUAGE_C      defined (C)
_POSIX_VERSION  defined (199506)
_XOPEN_VERSION  defined (4)
__mips          defined (MIPS arch)
__unix          defined (Unix)
_SYSTYPE_SVR4   defined (SYSV R4)
__sgi           defined (SGI)

char:           1
short:          2
int:            4
long:           8
float:          4
double:         8
size_t:         8
void *:         8
long double:    16      Warning: long double is an ANSI feature
long long:      8       Warning: long long is an ANSI feature


	(parte de la salida del siguiente codigo)


- tsizes.c ----------------------------------------------------------------
/*
 * HP-UX 9.x
 *		cc -Aa -D_HPUX_SOURCE
 * HP-UX
 *		cc -Ae
 *		cc -Ae +DA2.0W (64)
 * IRIX
 *		cc -o32
 *		cc -n32 -mips3
 *		cc -64 -mips3 (64)
 * Solaris
 *		cc -xarch=v9a (64)
 * Tru64
 *		cc (64)
 */
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>


#ifdef __STDC__
void main( void )
#else
void main()
#endif
{
	char		c;
	unsigned char	uc;

#ifdef __STDC__
	signed char	sc;
#endif


/* HP-UX defines __LP64__ */

#if defined(_LP64) || defined (__arch64__) || defined (__mips64) || defined (__LP64__)
#	define ARCH64 1
#endif

#ifdef __sgi
#if (_MIPS_SZPTR == 64)
#	define ARCH64 1
#endif
#endif
#if defined __alpha
#	define ARCH64 1
#endif

#ifdef ARCH64
#define D_WORD int
#else
#define D_WORD long
#endif

	static float	f[]={ 0.0, -10.34, 9.99e9, 0.1e-23 };
	static unsigned D_WORD l[]={0x00000000,0xC12570A4,0x5014DCD3,0x179ABE15};

	union {
		short int s;
		char c[2];
	} u;

	struct { char c; short int i; } block;

	u.c[0]=0x00;
	u.c[1]=0xaf;

#ifdef ARCH64
	puts("This is a 64 bits architecture");
#endif
printf("size of D_WORD is %d (should be %d)\n",sizeof(D_WORD),sizeof(float));

#ifdef __STDC__
	puts("__STDC__\tdefined (ANSI C compiler)");
#else
	puts("__STDC__\tnot defined");
#endif
#ifdef __STDC_EXT__
	puts("__STDC_EXT__\tdefined (ANSI C compiler + Extensions)");
#endif
#ifdef LANGUAGE_C
	puts("LANGUAGE_C\tdefined (C)");
#endif
#ifdef __cplusplus
	puts("__cplusplus\tdefined (C++)");
#endif


#ifdef _POSIX_VERSION
	printf("_POSIX_VERSION\tdefined (%d)\n", _POSIX_VERSION);
#endif
#ifdef _XOPEN_VERSION
	printf("_XOPEN_VERSION\tdefined (%d)\n", _XOPEN_VERSION);
#endif

/********
 * CPU
 */

/* PowerPC */

#ifdef __POWERC__
	puts("__POWERC__\tdefined (CW is generating code for the PowerPC)");
#endif
#ifdef __MC68020__
	puts("__MC68020__\tdefined (CW is generating code for the 68020)");
#endif
#ifdef __MC68881__
	puts("__MC68881__\tdefined (CW is generating code for the 68881)");
#endif
#ifdef __ppc__
	puts("__ppc__\t\tdefined (PowerPC arch)");
#endif
#ifdef ppc
	puts("ppc\t\tdefined (PowerPC arch)");
#endif

/* Intel */

#if defined (__i386)
	puts("__i386\t\tdefined (x86 arch)");
#endif
#if defined (i386)
	puts("i386\t\tdefined (x86 arch)");
#endif
#if defined(__i386__)
	puts("__i386__\tdefined (x86 arch)");
#endif
#if defined(M_I86)
	puts("M_I86\tdefined (x86 arch)");
#endif
#if defined(_M_IX86)
	puts("_M_IX86\tdefined (x86 arch)");
#endif

/* Alpha */

#if defined(__alpha)
	puts("__alpha\t\tdefined (Alpha)");
#endif
#if defined(__arch64__)
	puts("__arch64__\tdefined (Alpha, 64 bit)");
#endif

/* HP PA RISC */

#if defined(__hppa)
	 puts("__hppa\t\tdefined (HP PA RISC)");
#if defined ( _PA_RISC1_0 )
	 puts("_PA_RISC1_0\tdefined (HP PA RISC)");
#endif
#if defined ( _PA_RISC1_1 )
	 puts("_PA_RISC1_1\tdefined (HP PA RISC)");
#endif
#if defined ( _PA_RISC2_0 )
	 puts("_PA_RISC2_0\tdefined (HP PA RISC, 64 bit)");
#endif
#endif

/* Sparc */

#ifdef __sparc
	puts("__sparc\t\tdefined (SPARC arch)");
#endif

#ifdef __sparcv9
	puts("__sparcv9\tdefined (SPARC 64 arch)");
#endif

/* MIPS */

#ifdef __mips
	puts("__mips\t\tdefined (MIPS arch)");
#endif
#if defined (__mips64)
	puts("__mips64\tdefined (MIPS arch 64 bit)");
#endif

/********
 * Compiler
 */


#ifdef THINK_C
	puts("THINK_C\tdefined (this must be a Think C compiler whit Think extension active)");
#endif

#if	defined(__INTEL_COMPILER)
	puts("__INTEL_COMPILER\tdefined (this must be an Intel Compiler)");
#endif
#ifdef __MWERKS__ /* ALWAYS defined for CW */
	puts("__MWERKS__\tdefined (this must be a Metrowerks Code Warrior C compiler)");
#endif


#ifdef __GNUC__
	printf("__GNUC__\tdefined (this must be gcc %d)\n", __GNUC__);
#endif
#ifdef __SUNPRO_C
	printf("__SUNPRO_C\tdefined (Sun Compilers 0x%x)\n", __SUNPRO_C);
#endif
#ifdef __DECC
	printf("__DECC\t\tdefined (DEC Compilers)\n");
#endif
#ifdef __DECC_VER
	printf("__DECC_VER\tdefined (DEC Compilers 0x%x)\n", __DECC_VER);
#endif

#ifdef _MSC_VER
	printf("_MSC_VER\tdefined (Microsoft Compiler %d)\n", _MSC_VER);
#endif

/********
 * OS
 */

#ifdef __unix__
	puts("__unix__\tdefined (Unix)");
#endif
#ifdef __unix
	puts("__unix\t\tdefined (Unix)");
#endif


#ifdef __SVR4
	puts("__SVR4\t\tdefined (SYSV R4)");
#endif
#ifdef _SYSTYPE_SVR4
	puts("_SYSTYPE_SVR4\tdefined (SYSV R4)");
#endif
#if defined __svr4__
	puts("__svr4__\tdefined (SYSV R4)");
#endif

#ifdef SYSTYPE_BSD
	puts("SYSTYPE_BSD\tdefined (BSD)");
#endif
#ifdef _SYSTYPE_BSD
	puts("_SYSTYPE_BSD\tdefined (BSD)");
#endif


#ifdef __hpux
	puts("__hpux\t\tdefined (HP-UX)");
#endif
#ifdef _HPUX_SOURCE
	puts("_HPUX_SOURCE\tdefined (HP-UX source)");
#endif

#if ( defined __sun__ && !defined __svr4__ )
	puts("__sun__ && !__svr4__\tdefined (SunOS 4.x)");
#endif

#if defined __linux__
	puts("__linux__\tdefined (Linux)");
#endif

#if defined __osf__
	puts("__osf__\t\tdefined (Tru64/OSF)");
#endif

#if defined __convexc__
	puts("__convexc__\tdefined (cc on Convex)");
#endif

#if defined WIN32
	puts("WIN32\tdefined (Windows 95/98/NT/2000/XP)");
#endif

/********
 * Hardware
 */

#ifdef __APPLE__
	puts("__APPLE__\tdefined (Apple)");
#endif

/* http://developer.apple.com/technotes/tn2002/tn2071.html */
#if defined(__MACH__) && defined(__APPLE__)
	puts("__MACH__ && __APPLE__\tdefined (Probably gcc/pb in MacOS X)");
#endif

#if defined(macintosh)
	puts("macintosh\tdefined (Macintosh, MacOS 9.x or earlier)");
#endif

#if defined(__MACOS__)
	puts("__MACOS__\tdefined (MacOS, Probably MacOS 9.x or earlier)");
#endif

#ifdef __sun
	puts("__sun\t\tdefined (Sun Microsystems)");
#endif


#ifdef __sgi
	puts("__sgi\t\tdefined (SGI)");
#endif


	
	printf("\nchar:\t\t%d\n", (int)sizeof(char));
	printf("short:\t\t%d\n", (int)sizeof(short));
	printf("int:\t\t%d\n", (int)sizeof(int));
	printf("long:\t\t%d\n", (int)sizeof(long));
	printf("float:\t\t%d\n", (int)sizeof(float));
	printf("double:\t\t%d\n", (int)sizeof(double));
	printf("size_t:\t\t%d\n", (int)sizeof(size_t));
	printf("void *:\t\t%d\n", (int)sizeof(void *));
#ifndef ARCH64
	if ( sizeof (void *) == 8 )
		printf("\t\t\t64 bit architecture, not detected; fix source code!\n");
#endif


#ifdef __STDC__
	printf("long double:\t%d\t", (int)sizeof(long double));
	puts("Warning: long double is an ANSI feature");
#if defined(__hpux) && !defined (_POSIX_VERSION)
	printf("long long:\t%s\t", "Not supported on this HP-UX/cc release/cflags");
#else
	printf("long long:\t%d\t", (int)sizeof(long long));
	puts("Warning: long long is an ANSI feature");
#endif
#endif

	block.c = 'a';
	block.i = 1;
	
	printf("\nsizeof(char+short)=%d\n", (int)sizeof(block));
	printf("sizeof(char)+sizeof(short)=%d\n\n", (int)sizeof(char)+(int)sizeof(short));

	c=0xaf;
	uc=0xaf;

	if (c<0) puts("char is signed");
	else puts("char is unsigned");
	if (uc<0) puts("unsigned char is signed");
	else puts("unsigned char is unsigned");

#ifdef __STDC__
	sc=0xaf;
	if (sc<0) puts("signed char is signed");
	else puts("signed char is unsigned");
	puts("Warning: signed char is an ANSI feature");
#endif

	puts("\nfloat IEEE:");


	printf("%X\t%X\n%X\t%X\n%X\t%X\n%X\t%X\n\n",
		*(unsigned D_WORD*)&f[0], l[0],
		*(unsigned D_WORD*)&f[1], l[1],
		*(unsigned D_WORD*)&f[2], l[2],
		*(unsigned D_WORD*)&f[3], l[3] );

	fflush(stdout);

/* MacOS X */
#ifdef BYTE_ORDER
	printf("BYTE_ORDER defined (%d)\n",BYTE_ORDER);
#	if ( BYTE_ORDER == BIG_ENDIAN )
		printf("BYTE_ORDER is BIG_ENDIAN\n");
#	elif ( BYTE_ORDER == LITTLE_ENDIAN )
		printf("BYTE_ORDER is LITTLE_ENDIAN\n");
#	elif ( BYTE_ORDER == PDP_ENDIAN )
		printf("BYTE_ORDER is PDP_ENDIAN\n");
#	endif
#endif

#ifdef __BIG_ENDIAN__
	printf("__BIG_ENDIAN__ defined\n");
#endif

/* SGI IRIX */
#ifdef _MIPSEB
	printf("_MIPSEB defined (IRIX MIPS big endian)\n");
#endif
#ifdef _MIPSEL
	printf("_MIPSEL defined (IRIX MIPS little endian)\n");
#endif

	if ( u.s == 175 )
		puts("big-endian (MC680*0)");
	else
		puts("little-endian (80*86)");

}


---------------------------------------------------------------------------
-- 
finger spd@shiva.cps.unizar.es for PGP      /
.mailcap tip of the day:                   /             La vida es una carcel
application/ms-tnef; cat '%s' > /dev/null /           con las puertas abiertas
text/x-vcard; cat '%s' > /dev/null       /            (A. Calamaro)
Technical Details
Message-ID: <bjjsmo$djs$1@localhost.escomposlinux.org>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsmi-us.news.garr.it!NewsITBone-GARR!news.mailgate.org!newsfeed.wirehub.nl!news-hub.cableinet.net!blueyonder!marmolejo.escomposlinux.org!escomposlinux.org!not-for-mail
References: <bji3ts$iv42b$1@ID-148083.news.uni-berlin.de> <3F5C9E79.4030201@example.net>

Show Full Headers
Complete Article Headers
X-Google-Language: PORTUGUESE,ASCII
X-Google-Thread: f86c8,6bded6c0142ea4bd
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2003-09-08 23:41:34 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsmi-us.news.garr.it!NewsITBone-GARR!news.mailgate.org!newsfeed.wirehub.nl!news-hub.cableinet.net!blueyonder!marmolejo.escomposlinux.org!escomposlinux.org!not-for-mail
From: "J.A. Gutierrez" <spd@daphne.cps.unizar.es>
Newsgroups: es.comp.os.linux.programacion
Subject: Re: tamaño en bytes
Date: Tue, 9 Sep 2003 06:41:28 +0000 (UTC)
Organization: Rank
Lines: 445
Sender: "J.A. Gutierrez" <spd@shiva.cps.unizar.es>
Distribution: es
Message-ID: <bjjsmo$djs$1@localhost.escomposlinux.org>
References: <bji3ts$iv42b$1@ID-148083.news.uni-berlin.de> <3F5C9E79.4030201@example.net>
NNTP-Posting-Host: shiva.cps.unizar.es
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: localhost.escomposlinux.org 1063089688 13948 155.210.152.10 (9 Sep 2003 06:41:28 GMT)
X-Complaints-To: newsmaster@marmolejo.escomposlinux.org
NNTP-Posting-Date: Tue, 9 Sep 2003 06:41:28 +0000 (UTC)
User-Agent: tin/1.4.7-20030322 ("Suggestions") (UNIX) (IRIX64/6.2 (IP19))