[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
ffcall on FreeBSD
From: |
Kim Shrier |
Subject: |
ffcall on FreeBSD |
Date: |
Tue, 20 Mar 2001 03:00:59 -0600 |
I was experimenting with compiling the ffcall library on FreeBSD 4.2
and I ran into a problem with the test program(s). The test cases that
involve functions that return structures that consist of a single
float or double member don't work because the gcc compiler recognizes
that a structure that consists of a single float or double member can
be treated like a regular float or double variable. For example:
typedef struct { float x; } Float;
Float F_Ffd (Float a, float b, double c)
{
Float r;
r.x = a.x + b + c;
fprintf(out,"Float f(Float,float,double):({%g},%g,%g)",a.x,b,c);
fflush(out);
return r;
}
When this function is called in the following way:
Float F1={0.1};
float f2=0.2;
double d3=0.3;
Float Fr;
Fr = F_Ffd(F1,f2,d3);
The gcc 2.95.2 compiler treats this function as if it were returning
a float variable instead of a structure that contains a float member.
At the machine language level, this means that the return value is
in a floating point register, instead of being returned in eax or on
the stack.
There are 2 approaches I can use to get the tests to succeed. I can
modify the definition of Float so that the gcc compiler doesn't
optimize the code. For instance, by redefining Float to be:
typedef struct { float x; int y; } Float;
The tests succeed because the return value is returned in the eax, edx
register pair instead of a floating point register. The av_start_struct
macro correctly handles this case.
The other approach is to change the tests.c source to use av_start_float
instead of av_start_struct. This works but it requires the programmer
to know that a structure with one float element is treated the same as
a float when it is a return value.
After going through all this, I went to the FTP site for ffcall and
looked at the latest version, 1.8. As of version 1.7, support for
structures with float and double members appears to be dropped. So
my question is, which version of ffcall should I be using. I looked
at the source for GSFFCallInvocation and it looks like the 1.6b version
of ffcall should work on FreeBSD 4.2 as is.
Any recommendations?
Thanks,
Kim
--
Kim Shrier - principal, Shrier and Deihl - mailto:kim@tinker.com
Remote Unix Network Admin, Security, Internet Software Development
Tinker Internet Services - Superior FreeBSD-based Web Hosting
http://www.tinker.com/
- ffcall on FreeBSD,
Kim Shrier <=