[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gm2] complex types
From: |
Gaius Mulley |
Subject: |
Re: [Gm2] complex types |
Date: |
Mon, 15 Dec 2008 19:50:33 +0000 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) |
From: Gaius Mulley <address@hidden>
Subject: Re: [Gm2] complex types
To: Andreas Fischlin <address@hidden>
Cc: GM2 <address@hidden>
Andreas Fischlin <address@hidden> writes:
> Arn't C library conversion routines already longreal? MathLib0
Hi Andreas,
ahh I believe there could be a problem here..
> definition looks similar to this (within RAMSES/RASS):
> DEFINITION FOR C MODULE CMath;
>
> PROCEDURE sqrt(x : LONGREAL) : LONGREAL;
> PROCEDURE sin (x : LONGREAL) : LONGREAL;
> PROCEDURE cos (x : LONGREAL) : LONGREAL;
> PROCEDURE exp (x : LONGREAL) : LONGREAL;
> PROCEDURE log (x : LONGREAL) : LONGREAL;
> PROCEDURE atan(x : LONGREAL) : LONGREAL;
>
> END CMath.
> PROCEDURE Sin(x: REAL): REAL;
> BEGIN
> RETURN CMath.sin(x)
^^^
> END Sin;
I think there might be a portability problem with the above (in gm2) -
as the C function sin is defined to take and return a 'double' whereas
in gm2 LONGREAL maps onto a 'long double'.
cut from 'man 3 sin':
#include <math.h>
double sin(double x);
float sinf(float x);
long double sinl(long double x);
I guess it works on systems where sizeof(double)==sizeof(long double)
or with Modula-2 compilers where TSIZE(LONGREAL)==sizeof(double). But
it will fail with gm2 as
LONGREAL == long double
REAL == double
SHORTREAL == float
For example:
address@hidden:~/GM2$ gm2 -g -fcpp -c sizes.mod
address@hidden:~/GM2$ gm2 -g -fcpp sizes.mod
address@hidden:~/GM2$ ./a.out
size of CHAR is 1 bytes
size of INTEGER is 4 bytes
size of CARDINAL is 4 bytes
size of LONGINT is 8 bytes
size of LONGCARD is 8 bytes
size of SHORTREAL is 4 bytes
size of REAL is 8 bytes
size of LONGREAL is 16 bytes
size of BITSET is 4 bytes
address@hidden:~/GM2$ gcc sizes.c
address@hidden:~/GM2$ ./a.out
size of char is: 1 bytes
size of int is: 4 bytes
size of unsigned int is: 4 bytes
size of long int is: 8 bytes
size of long unsigned int is: 8 bytes
size of long long int is: 8 bytes
size of long long unsigned int is: 8 bytes
size of float is: 4 bytes
size of double is: 8 bytes
size of long double is: 16 bytes
So specifically at position "^^^" we see that gm2 will attempt to pass
a "long double" parameter to a C function expecting a "double"
regards,
Gaius
- [Gm2] complex types, Gaius Mulley, 2008/12/14
- Re: [Gm2] complex types, Michael Lambert, 2008/12/14
- Re: [Gm2] complex types, Andreas Fischlin, 2008/12/14
- Re: [Gm2] complex types, Michael Lambert, 2008/12/14
- Re: [Gm2] complex types, Gaius Mulley, 2008/12/14
- Re: [Gm2] complex types, Andreas Fischlin, 2008/12/14
- Re: [Gm2] complex types, Gaius Mulley, 2008/12/15
- Re: [Gm2] complex types, Andreas Fischlin, 2008/12/15
- Re: [Gm2] complex types, Gaius Mulley, 2008/12/15
- Re: [Gm2] complex types,
Gaius Mulley <=
- Re: [Gm2] complex types, Andreas Fischlin, 2008/12/15
- Re: [Gm2] complex types, Michael Lambert, 2008/12/15
- Re: [Gm2] complex types, Andreas Fischlin, 2008/12/15
- Re: [Gm2] complex types, Michael Lambert, 2008/12/15
- Re: [Gm2] complex types, Andreas Fischlin, 2008/12/16
- Re: [Gm2] complex types, Michael Lambert, 2008/12/16