|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Overloaded functions
In my header file, I have the following function prototypes:
Code:
int abs(int); float abs(float); Code:
int abs(int x)
{
if(x>=0)
return x;
else
return -x;
}
float abs(float x)
{
if(x>=0)
return x;
else
return -x;
}
|
|
#2
|
||||
|
||||
|
Re: Overloaded functions
If I'm not mistaken, overloadable functions was added in C++ and is not possible in C.
|
|
#3
|
||||
|
||||
|
Re: Overloaded functions
Quote:
![]() |
|
#4
|
||||
|
||||
|
Re: Overloaded functions
Well for this example, you could easily just cast to int and use the same function. (You could cast to int in all cases, even when it already is an int, to maintain uniformity). I can't really think of any other way.
|
|
#5
|
||||
|
||||
|
Re: Overloaded functions
IMHO, no one would ever want to work with floating point at all in an embedded system like this. It makes no sense.
JMHO... |
|
#6
|
|||||
|
|||||
|
Re: Overloaded functions
The only thing I can think of is to use a macro
Code:
#define ABS(num) ( ((num) >= 0) ? (num) : (0 - (num)) ) But I still wouldn't use floating point. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| New Serial Port Driver | Kevin Watson | Programming | 16 | 09-01-2005 01:56 |
| Trigometric Functions | cibressus53 | Programming | 4 | 25-10-2004 21:49 |
| Do you write functions for your code? | Max Lobovsky | Programming | 26 | 11-03-2004 07:04 |
| Important functions of a first robot? | Ianworld | General Forum | 5 | 15-04-2003 13:29 |
| Primary Functions Poll | Ben Mitchell | Rules/Strategy | 1 | 16-02-2003 02:10 |