Brad Boisen
Brad Boisen

Reputation: 1

Parameter Names (without types) in Function Declaration

So, I'm working on an assignment and my teacher didn't quite explain functions very well. I'll save some time and show the main segment where the error occurs:

 #include <stdio.h>
 6  int main(void)
 7  {
 8   double Depth;
 9   double celsius_at_depth(Depth);
10  {
11   10*(Depth)+20;
12  }

And the error:

GHP#4.c:9:2: warning: parameter names (without types) 
in function declaration [enabled by default]
double celsius_at_depth(Depth);
^

Sorry about formatting, I wanted it to be easier to see. isn't double supposed to be the parameter type for the function celsius_at_depth?

EDIT: I've looked up the error on the site, but I didn't quite see it in the same formatting as my code, so I felt it best to post anew

Upvotes: 0

Views: 21311

Answers (2)

Anand Tripathi
Anand Tripathi

Reputation: 1

just remove the data type , when calling the function ... so instead of , double celsius_at_depth(Depth); write celsius_at_depth(Depth);

Upvotes: -2

Iharob Al Asimi
Iharob Al Asimi

Reputation: 53006

Defining a function inside another function is a non standard extension of gcc AFAIK, so it's not a good idea.

To declare the function you first need to move it outside main() so

double celsius_at_depth(double depth);

and then you can call it in main like this

#include <stdio.h>
int main(void)
{
    double depth = 10;
    printf("celsius_at_depth(%f) = %f\n", depth, celsius_at_depth(depth))
    return 0;
}

then the function definition

double celsius_at_depth(double depth);
{
    return 10 * depth + 20;
}

Upvotes: 2

Related Questions