Link to home
Start Free TrialLog in
Avatar of KarenNewton
KarenNewton

asked on

How can I write my own "round" function (Solaris, language C)

I'm trying to compile an existing file on Solaris 5.10, using gcc. This is the command I'm typing, very simple:

gcc -c round.c -I/include/general -o round.o

Now the round.c file contains a method "round" that takes 2 arguments. I don't have the option of changing the file or function name. When I try to compile this I get the following errors:

round.c:9: error: conflicting types for 'round'
round.c:9: error: conflicting types for 'round'

An include file that is referenced by round.c does include <math.h> .Seems there already is a system round function that wants only 1 argument. How do I have gcc ignore the round method from <math.h> and thus get rid of this conflicting types error?

Note that on another Solaris machine, Solaris 5.6, I can compile round.c in the same manner without any problem whatsoever.

Any help is appreciated!
Thanks,
Karen
Avatar of Infinity08
Infinity08
Flag of Belgium image

Can you leave out the #include <math.h> ?
Can you give your function a different name than 'round' ? I know you said you can't, but why not ?
Can you post the round.c file ?


>> Note that on another Solaris machine, Solaris 5.6, I can compile round.c in the same manner without any problem whatsoever.

Are you sure that was with a (compliant) C compiler ? (not a C++ compiler for example)
Avatar of KarenNewton
KarenNewton

ASKER

What we are trying to do is to migrate code over without any changes. Our round function is used in several files, so that's the last resort I want to take is to modify files.

You asked if I was sure it was a compliant C compiler - I used gcc on both machines. On the Solaris 5.6 machine, gcc is version 2.8.1. On the Solaris 5.10 machine, gcc is version 3.4.3

Copy of round.c is included too - thank you for any and all help.

Karen
#include        "mmd.h"
 
double round(double  value, int i_num) 
{
 
        double val=0,val1;
        char str[80];
 
  if (value < 0.0)
     val = (value * pow(10.0, (double)i_num) ) - 0.5;
        else
     val = (value * pow(10.0, (double)i_num) ) + 0.5;
 
        modf(val, &val1);
 
        value = val1 / pow(10.0, (double)i_num);
 
   return(value);
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much, using -ansi worked like a charm!
>> Thank you very much, using -ansi worked like a charm!

Good :)