Dean
Dean

Reputation: 1153

Use of macros but had implicit declaration of function error

I'm trying to run the following code, but I cannot compile it as my IDE complained for the following reason.

H:\C\sandBox.c|11|warning: implicit declaration of function 'RECIPROCAL'|

I don't know why my code doesn't work. Can you please help?

#include <stdio.h>
# RECIPROCAL(number) (1.0 / (number))

int main()
{
    float   counter;    /* Counter for our table */

    for (counter = 0.0; counter < 10.0;
     counter += 1.0) {

        printf("1/%f = %f\n", counter, RECIPROCAL(counter));
    }
    return (0);
}

Upvotes: 0

Views: 4044

Answers (2)

user557219
user557219

Reputation:

That’s because you need to use #define to define a preprocessor macro.

Change:

# RECIPROCAL(number) (1.0 / (number))

to

#define RECIPROCAL(number) (1.0 / (number))

Upvotes: 3

MByD
MByD

Reputation: 137322

You forgot define:

#define RECIPROCAL(number) (1.0 / (number))

Upvotes: 2

Related Questions