Error using powf () function in C

I wrote this C code to find the value for three squares.

#include <stdio.h>
#include <math.h>
int main( void )
{
    float a;
    a = powf( 3, 2 );
    printf( "\n%f\n", a );
    return 0;
}

I get a warning implicit declaration of function 'powf'even when the library is on math.hand -lmin the terminal command:

gcc -o test.exe -ansi -Wall test.c -lm

My version of gcc is 4.2.2 if that helps.

+4
source share
2 answers

powfadded to C99. Option is -ansiequivalent -std=c89. You need to use the flag -std=c99.

gcc -o test.exe -std=c99 -Wall test.c -lm
+7
source

The problem is the parameter -ansi. It is equivalent -std=c90.

As the man page for powf reports , you need to use-std=c99

+4
source

Source: https://habr.com/ru/post/1695280/


All Articles