Operating System - HP-UX
1827474 Members
2015 Online
109965 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".
Steven Schweda
Honored Contributor

Re: Help - cant compile c program with function

> [...] you shouldn't code that way.

No argument here. I claim that
IMPLICIT NONE
was the best thing that ever happened to
FORTRAN. The amazing thing is that someone
thought that "implicit int" was a good idea
for C.
TwoProc
Honored Contributor

Re: Help - cant compile c program with function

You're right Steve.

I can remember wading through fortran just absolutely loaded with implicits from all over the place. Nasty. Really nasty when the code wasn't yours, and was written over 25 years ago, and no-one was familiar with it. All I could do was make subroutines

The worst I ever saw was in a C program that I became the chief owner of, it was a total of 250K lines of code, and in the middle of one of the longest pieces, I found the following indented over about 200 spaces to the right.

m++;

I wrote an awk script to give me a look at program flow and variable declarations. I never found it where "m" was declared, and I never found it became instantiated. The debugger was crud (it was an off brand C compiler, I forget the name) so putting a "watch" on m was impossible to see if I could watch it come to life. Ugh.

So, I commented the line out and recompiled. And nothing worked.

:-)

Dave, no points for this please, it was just an old bad memory I wanted to share for some reason.
We are the people our parents warned us about --Jimmy Buffett