gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gm2] More about LONGINT fixes


From: Gaius Mulley
Subject: Re: [Gm2] More about LONGINT fixes
Date: 16 Nov 2004 23:17:03 +0000
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Hi,

I believe I've fixed LONGINT constant for an opteron based system..
It is slightly more tricky for 32 bit systems due to the data type
correspondence between C and Modula-2 which is outlined below:

GNU Modula-2              GNU C
======================================
INTEGER                   int
LONGINT                   long int
SHORTINT                  short int
CARDINAL                  unsigned int
LONGCARD                  long unsigned int
SHORTCARD                 short unsigned int
BOOLEAN                   int
REAL                      double
LONGREAL                  long double
SHORTREAL                 float
CHAR                      char

on a 32 bit i386 this program yields the following results:


#include <sys/types.h>
#include <unistd.h>

#define SIZEOF(X)  printf("size of " #X " is %d bytes\n", sizeof(X));

main()
{
  SIZEOF(int)
  SIZEOF(short int)
  SIZEOF(long int)
  SIZEOF(long long int)
  SIZEOF(unsigned int)
  SIZEOF(unsigned short int)
  SIZEOF(unsigned long int)
  SIZEOF(unsigned long long int)
  SIZEOF(off_t)
}


size of int is 4 bytes
size of short int is 2 bytes
size of long int is 4 bytes
size of long long int is 8 bytes
size of unsigned int is 4 bytes
size of unsigned short int is 2 bytes
size of unsigned long int is 4 bytes
size of unsigned long long int is 8 bytes
size of off_t is 4 bytes

whereas on a LP64 model (opteron) Long Pointer 64 bits, ints are 32
bit. It yields:

size of int is 4 bytes
size of short int is 2 bytes
size of long int is 8 bytes
size of long long int is 8 bytes
size of unsigned int is 4 bytes
size of unsigned short int is 2 bytes
size of unsigned long int is 8 bytes
size of unsigned long long int is 8 bytes
size of off_t is 8 bytes

so should LONGINT map onto long long int or should we introduce
LONGLONGINT ?

Introducing LONGLONGINT - is very transparent to users and it leaves
little confusion when generating definition modules for C, it is also
much more portable between GNU based architectures ie gm2 + gcc.
As you can see I'm leaning towards this solution, but I'm open
to other solutions if a good case could be made? I don't like
compiler switches for these cases as one might want both LONGINT and
LONGLONGINT in a single module to map onto a C library possibly,

any comments?

Gaius



reply via email to

[Prev in Thread] Current Thread [Next in Thread]