Looking for a gcc flag [Archive] - C Board

PDA

View Full Version : Looking for a gcc flag


JLWinsett
12-26-2002, 09:41 AM
I learned the other day that C likes to automatically convert a float to a double when it gets passed to a subrountine. Is there a flag in gcc which will keep this from happening? I have tried using -ffloat-store and -fallow-single-precision w/ -traditional, but that didn't work. I didn't write the code which I am having trouble with, but the floats MUST stay floats when they get passed to the subroutine, or the whole thing crashes with a segmentation fault. I'm sorry, but I can't include any of the code. I'm wondering, however, if it has something to do with the fact that some of the floats are actually #defines, which then get passed directly to the subroutine, ie


#define X=1.0;

test(X);

I appreciate any help you might offer!

JLWinsett
12-26-2002, 10:40 AM
Unfortunately, there is not a particularly easy way for me to give you a snippet. However, let me try to explain a little better what is happening when we get the segmentation fault.

We are reading in a VERY large set of data, then trying to display it using XView. When I run the program which actually does the display, it creates the frame and does everything correctly, but at the call

xv_main_loop(base_frame)

we get the segmentation fault. The window with the axes actually pops up, but at this call, which I assume actually tries to display our data, the window disappears and I get the error. Both my supervisor, and the code author believe that the problem lies in the fact that C converts floats to doubles when they are passed to a subroutine, so that the data is much bigger than it should be. I know C ok, but I have never done any programming with XView before they asked me to look into this problem, so I kinda have to go with what they tell me. I'm sorry that this isn't more help, but I appreciate your response!

Prelude
12-26-2002, 10:52 AM
>but the floats MUST stay floats when they get passed to the subroutine, or the whole thing crashes with a segmentation fault.
That doesn't sound quite right, a segmentation fault has nothing to do with relatively safe type conversions, it means you're doing something naughty with a pointer.

-Prelude

JLWinsett
12-26-2002, 11:16 AM
From the IBM XLFortran website, "C programs automatically convert float values to double, and short integer values to integer when calling an unprototyped C function."

Now, this statement leads me to a new question. I kinda thought that you HAD to have a prototype, or C would complain. However, in looking at some of the code, I find the following:

In main, there is a call to a subroutine I will call pick:
n=pick(x,y,z);

where x,y,z are defined
float *x;
int y;
float z=-0.1;

pick is defined in pick.c as
int pick(float x, int y, float z){
...code here...
}

pick is not defined anywhere else.

Does the above represent the prototype for pick? If so, then Prelude, I agree with you ,and want to know what the heck is going on! If it does not, then the stuff I read on the IBM page becomes valid, and I need to know how to keep that from happening. I realize that this may be a stupid question, but I kinda learned C on the fly, so please bear with me. Thanks!

JLWinsett
12-26-2002, 11:39 AM
Should have included this in the last post:

float *x;
int y;
float x=-0.1;

x = (float *) calloc(n,sizeof(float));
for (i=0;i<n;i++)
x[i] = 0;

t = pick(x,y,z);

It is possible that in the call to pick, he meant *x, but I'm not sure. This isn't the only place where this occurs.