Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2009-04-21
5
Medium Priority
?
2,620 Views
Last Modified: 2013-12-13
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
0
Comment
Question by:KarenNewton
  • 3
  • 2
5 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 24194938
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)
0
 

Author Comment

by:KarenNewton
ID: 24195115
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

0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 2000 total points
ID: 24195397
>> On the Solaris 5.6 machine, gcc is version 2.8.1

That one is a bit old, and since 'round' was added in C99, it didn't support it yet, so that's why it compiled.

C99 added this 'round' function to <math.h> :

        double round(double x);


>> On the Solaris 5.10 machine, gcc is version 3.4.3

I'm not sure whether this version of gcc already included support for the new 'round' function, but it seems it does (you can easily check that by doing a grep for 'round' in the math.h header file).

What you could try, is compile it in old standard mode using the -ansi compiler flag.
0
 

Author Closing Comment

by:KarenNewton
ID: 31572759
Thank you very much, using -ansi worked like a charm!
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24196484
>> Thank you very much, using -ansi worked like a charm!

Good :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Web hosting control panels were first developed to make it faster and easier for most users to set up and operate websites. The graphical user interface (GUI) allows users to perform tasks by pointing and clicking rather than typing highly specific…
Conducting a customer service survey used to be as straightforward as sending a template email out using checkboxes and numerical rating systems to measure satisfaction.
This video demonstrates how to use each tool, their shortcuts, where and when to use them, and how to use the keyboard to improve workflow.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question