Objectmix
Tags Register Mark Forums Read

Compiler cannot differentiate between fmin(double x[])) and fmin(double, double) : C

This is a discussion on Compiler cannot differentiate between fmin(double x[])) and fmin(double, double) within the C forums in Programming Languages category; Dear All, It is my understanding that the two functions: double fmin(double x[]); double fmin(double, double ); are different functions and the compiler should be able to figure out which one to use. However, the following test program fails to compile on my Mac: ------------------------ #include<stdio.h> double myfunc(double x[]) {}; double myfunc(double, double) {}; int main(){} ------------------------ because it cannot tell the difference between the two functions. Is this behaviour correct? -- comp.lang.c.moderated - moderation address: clcm@plethora.net...


Object Mix > Programming Languages > C > Compiler cannot differentiate between fmin(double x[])) and fmin(double, double)

C comp.lang.c usenet archive

Reply

 

LinkBack Thread Tools
  #1  
Old 04-03-2004, 08:13 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Compiler cannot differentiate between fmin(double x[])) and fmin(double, double)

Dear All,

It is my understanding that the two functions:

double fmin(double x[]);
double fmin(double, double );

are different functions and the compiler should be able to figure out
which one to use. However, the following test program fails to compile
on my Mac:

------------------------
#include<stdio.h>
double myfunc(double x[]) {};
double myfunc(double, double) {};

int main(){}
------------------------

because it cannot tell the difference between the two functions. Is
this behaviour correct?
--
comp.lang.c.moderated - moderation address: clcm@plethora.net
Reply With Quote
  #2  
Old 04-05-2004, 02:41 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: Compiler cannot differentiate between fmin(double x[])) and fmin(double, double)

Sin Lee Huang wrote:

> Dear All,
>
> It is my understanding that the two functions:
>
> double fmin(double x[]);
> double fmin(double, double );
>
> are different functions and the compiler should be able to figure out
> which one to use.


Your understanding is incorrect. If you want that kind of behavior, use
C++. Just name the functions differently: that's what C++ does behind
your back, anyway. And if you want to use C99, you'll have to rename
the first one, since the second is a standard function:

7.12.12.3 The fmin functions
Synopsis
#include <math.h>
double fmin(double x, double y);
float fminf(float x, float y);
long double fminl(long double x, long double y);
Description
The fmin functions determine the minimum numerici value
of their arguments.
Returns
The fmin functions return the minimum numeric value of
their arguments.
--
comp.lang.c.moderated - moderation address: clcm@plethora.net
Reply With Quote
  #3  
Old 04-05-2004, 02:41 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: Compiler cannot differentiate between fmin(double x[])) and fmin(double, double)

On 04 Apr 2004 01:13:19 GMT, sinleeh@hotmail.com (Sin Lee Huang) wrote
in comp.lang.c.moderated:

> Dear All,
>
> It is my understanding that the two functions:
>
> double fmin(double x[]);
> double fmin(double, double );


Your understanding is incorrect, as far as the C language standard is
concerned. There are three versions of the fmin() function, namely
fmin() for doubles, fminf() for floats, and fminl() for long doubles.
If you include <tgmath.h>, you can use fmin() generically, with the
long double version called if either argument is a long double, and
the float version called if both arguments are floats.

But there is no standard version of fmin() that accepts a pointer of
any kind to any type.

> are different functions and the compiler should be able to figure out
> which one to use. However, the following test program fails to compile
> on my Mac:
>
> ------------------------
> #include<stdio.h>
> double myfunc(double x[]) {};
> double myfunc(double, double) {};


The program should fail to compile because you have two different and
incompatible definitions for the function "myfunc". If you want
function overloading, you are using the wrong language.
comp.lang.c++(.moderated) are down the hall to the right.

>
> int main(){}
> ------------------------
>
> because it cannot tell the difference between the two functions. Is
> this behaviour correct?


Yes, because C is not C++. Not on a Mac or anywhere else.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
--
comp.lang.c.moderated - moderation address: clcm@plethora.net
Reply With Quote
  #4  
Old 04-05-2004, 02:42 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: Compiler cannot differentiate between fmin(double x[])) and fmin(double, double)

Sin Lee Huang wrote:

> Dear All,
>
> It is my understanding that the two functions:
>
> double fmin(double x[]);
> double fmin(double, double );
>
> are different functions and the compiler should be able to figure out
> which one to use.


You are talking about a language that is not C. In C, you cannot have more
than one function called fmin(). Maybe you should take your problem to
comp.lang.c++.moderated.

Kurt Watzka
--
comp.lang.c.moderated - moderation address: clcm@plethora.net
Reply With Quote
  #5  
Old 04-05-2004, 02:42 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: Compiler cannot differentiate between fmin(double x[])) and fmin(double, double)

Sin Lee Huang <sinleeh@hotmail.com> wrote:
> Dear All,


> It is my understanding that the two functions:


> double fmin(double x[]);
> double fmin(double, double );


> are different functions and the compiler should be able to figure out
> which one to use.


This understanding is incorrect. You appear to be mixing up the C++
and C programming languages. Only the second form of fmin() shown
above is a C standard library function (as of C99). Generally, C
doesn't support overloaded functions, i.e. functions of the same with
different parameter lists.

--
Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
--
comp.lang.c.moderated - moderation address: clcm@plethora.net
Reply With Quote
  #6  
Old 04-05-2004, 02:42 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: Compiler cannot differentiate between fmin(double x[])) and fmin(double, double)

Sin Lee Huang escreveu:
> Dear All,
>
> It is my understanding that the two functions:
>
> double fmin(double x[]);
> double fmin(double, double );
>
> are different functions and the compiler should be able to figure out
> which one to use.


In C they are different functions but you gave them the same name and
the compiler is not able to determine which is what.

So you should give them different names or switch to C++ where what you
willing to do is allowed (is called 'overloading' of functions).

--
Cesar Rabak
--
comp.lang.c.moderated - moderation address: clcm@plethora.net
Reply With Quote
  #7  
Old 04-05-2004, 03:24 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: Compiler cannot differentiate between fmin(double x[])) and fmin(double, double)

On 04 Apr 2004 01:13:19 GMT, sinleeh@hotmail.com (Sin Lee Huang)
wrote:

>Dear All,
>
>It is my understanding that the two functions:
>
>double fmin(double x[]);
>double fmin(double, double );
>
>are different functions and the compiler should be able to figure out
>which one to use. However, the following test program fails to compile
>on my Mac:


C does not have function overloading.

>
>------------------------
>#include<stdio.h>
>double myfunc(double x[]) {};
>double myfunc(double, double) {};
>
>int main(){}
>------------------------
>
>because it cannot tell the difference between the two functions. Is
>this behaviour correct?




<<Remove the del for email>>
--
comp.lang.c.moderated - moderation address: clcm@plethora.net
Reply With Quote
  #8  
Old 04-05-2004, 03:27 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: Compiler cannot differentiate between fmin(double x[])) and fmin(double, double)

Sin Lee Huang wrote:
> Dear All,
>
> It is my understanding that the two functions:
>
> double fmin(double x[]);
> double fmin(double, double );
>
> are different functions and the compiler should be able to figure out
> which one to use.


No, your understanding is incorrect. The feature you refer to is called
function overloading and is not a part of the C programming language.
Were you thinking of C++?


--
John Tsiombikas (Nuclear / the Lab)
nuclear@siggraph.org
http://thelab.demoscene.gr/nuclear/
--
comp.lang.c.moderated - moderation address: clcm@plethora.net
Reply With Quote
  #9  
Old 04-05-2004, 03:33 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: Compiler cannot differentiate between fmin(double x[])) and fmin(double, double)

Sin Lee Huang <sinleeh@hotmail.com> wrote
in <clcm-20040403-0004@plethora.net>:
# Dear All,
#
# It is my understanding that the two functions:
#
# double fmin(double x[]);
# double fmin(double, double );
#
# are different functions and the compiler should be able to figure out
# which one to use.

This may be true for C++, but in C you can not declare prototypes
for the same function with different argument lists. C does not
support polymorphism.

Regards,

Jens
--
Jens Schweikhardt http://www.schweikhardt.net/
SIGSIG -- signature too long (core dumped)
--
comp.lang.c.moderated - moderation address: clcm@plethora.net
Reply With Quote
  #10  
Old 04-08-2004, 04:15 AM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: Compiler cannot differentiate between fmin(double x[])) and fmin(double, double)

"Sin Lee Huang" <sinleeh@hotmail.com> wrote in message
news:clcm-20040403-0004@plethora.net...
>
> It is my understanding that the two functions:
>
> double fmin(double x[]);
> double fmin(double, double );
>
> are different functions and the compiler should be able to figure out
> which one to use.


C does not support this. C++ does (as function overloading).
--
comp.lang.c.moderated - moderation address: clcm@plethora.net
Reply With Quote
Reply

Thread Tools


Similar Threads

Thread Thread Starter Forum Replies Last Post
fast copy from double[] to double[,] usenet CSharp 2 10-05-2007 10:02 AM
Double vs double usenet CSharp 8 09-10-2007 01:35 AM
'System.ArithmeticException was unhandled' at System.Double.CompareTo(Double value) when comparing with Double.NaN usenet DOTNET 0 05-14-2007 08:13 AM
double '*' usenet Java 1 12-22-2004 12:32 PM
Error in "double = double - double" statement usenet basic.visual 3 01-23-2004 06:06 AM


All times are GMT -5. The time now is 05:37 PM.