Looking for a gcc flag

This is a discussion on Looking for a gcc flag within the Linux Programming forums, part of the Platform Specific Boards category; I learned the other day that C likes to automatically convert a float to a double when it gets passed ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    4

    Looking for a gcc flag

    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!

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    4

    More info on my problem

    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!

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >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
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    4
    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!

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    4
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 10:38 AM
  2. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 09:36 PM
  3. Replies: 4
    Last Post: 09-02-2007, 09:47 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  5. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 07:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21