Operating System - HP-UX
1751738 Members
5700 Online
108781 Solutions
New Discussion юеВ

Help - cant compile c program with function

 
SOLVED
Go to solution
Dave Chamberlin
Trusted Contributor

Help - cant compile c program with function

Been awhile since I did any c programs with function declarations. This gives error 1584 (inconsistant type declaration).
11 REPLIES 11
Matti_Kurkela
Honored Contributor
Solution

Re: Help - cant compile c program with function

You need to list the types in your function declaration too. Listing them in the function prototype only is not enough.

Change:
----
dc(a,b)
{
----
to:
----
double dc(double a, double b)
{
----

MK
MK
Dave Chamberlin
Trusted Contributor

Re: Help - cant compile c program with function

The 1584 error is still there after changing the function to dc(double a, double b). Also tried chaning the declaration to double dc(double a, double b)
Dennis Handly
Acclaimed Contributor

Re: Help - cant compile c program with function

>MK: Listing them in the function prototype only is not enough.

It would also help if the prototype was at file scope.
Dennis Handly
Acclaimed Contributor

Re: Help - cant compile c program with function

>Also tried changing the declaration to: double dc(double a, double b)

What's the current source look like?
Dave Chamberlin
Trusted Contributor

Re: Help - cant compile c program with function

#include
#include


int main(void)
{
double a,b,intg;
double dc(double a,double b);


a=1.0;
b=2.0;

intg=dc(a,b);
printf("sum is %g\n",intg);
}

dc(double a,double b)
{
double q;
q=a+b;
return q;
}
James R. Ferguson
Acclaimed Contributor

Re: Help - cant compile c program with function

Hi Dave:

You didn't follow what Matti wrote:

...
double dc(double a, double b)
...

Regards!

...JRF...
Dave Chamberlin
Trusted Contributor

Re: Help - cant compile c program with function

That did it - thanks!
Steven Schweda
Honored Contributor

Re: Help - cant compile c program with function

This is (well-designed) C, so no type in a
declaration is equivalent to "int", so:
dc( [...]
is equivalent to:
int dc( [...]
which is "inconsistant" with:
double dc( [...]


Does the message actually have "inconsistent"
spelled wrong, or was that your contribution?
Dennis Handly
Acclaimed Contributor

Re: Help - cant compile c program with function

>Steven: This is (well-designed) C,

But it is obsolescent in C99, so you shouldn't code that way.

>Does the message actually have "inconsistent"
spelled wrong?

No, the PA compiler gets that right: :-)
cc: error 1584: Inconsistent type declaration: "dc".
cc: error 1711: Inconsistent parameter list declaration for "dc".