Home > Mobile >  Problem with function declaration in C when the 1st argument is a struct type
Problem with function declaration in C when the 1st argument is a struct type

Time:10-23

I am using a C code for some purpose written by some other person. While compiling the program :

warning: implicit declaration of function ‘shine’ [-Wimplicit-function-declaration

I am giving some part of the code below:

struct attribute
{
    int type, symb;      
    float lower, upper;
} examples[MaxExs][MaxAtts];

Below is the code where inside func1(), shine() is called.

int func1()
{
    int e, r, nstrule;
    float lwstdist;
    ...
    shine(examples[e], &nstrule, &lwstdist, e);
    ...
}

Below is the function definition for shine().

int shine(ex, nstrule, lwstdist, leftout) 
struct attribute ex[];
int *nstrule, leftout;
float *lwstdist;
{
    ...
}

I just want to remove that warning. So I wanted to declare that at the start of the code. I tried using:

int shine(xxx, int*, float*, int);

I don't know whether I am doing it correctly and what will be in place of xxx. I am new to C. So I am unable to figure out. Along with this help if I can get some material to go through for this particular thing that will be a great help.

CodePudding user response:

You need to place a forward declaration of struct attribute.

struct attribute;
int shine(struct attribute[], int*, float*, int);

Btw. Unnamed function parameters are not standard C. Though many compilers accept as it is allowed in C and trivial to implement.

This feature will be added to C in the upcomming C23 standard.

  • Related