PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label math.h. Show all posts
Showing posts with label math.h. Show all posts

Thursday, April 28, 2022

[FIXED] Where did sincos go? (gcc c)

 April 28, 2022     c, gcc, math.h, warnings     No comments   

Issue

Couple days ago it was working fine, but trying to use again today, my code editor cannot find sincos anymore and GCC throws me a warning that it cannot find sincos when compiling.

Here's the code:

// file: main.c 

#include <math.h>                                                                                                  
int main() {                                                                                                                         
    double sin, cos;                                                                                                     
    sincos(0.0, &sin, &cos);                                                                                             
    return 0;                                                                                                    
}        

Using gcc:

$ gcc main.c -lm

   x.c: In function ‘main’:
x.c:5:2: warning: implicit declaration of function ‘sincos’ [-Wimplicit-function-declaration]
    5 |  sincos(0.0, &sin, &cos);
      |  ^~~~~~
x.c:5:2: warning: incompatible implicit declaration of built-in function ‘sincos’
x.c:2:1: note: include ‘<math.h>’ or provide a declaration of ‘sincos’
    1 | #include <math.h>
  +++ |+#include <math.h>
    2 |

It says I should include math.h yet I do. It says it can't find sincos yet it compiles and runs fine. I'm just annoyed by those warnings. Anyone knows what's wrong?


Solution

Add the following to the top of the file to enable the gnu extension:

#define _GNU_SOURCE
#include <math.h>

This will prevent the warnings. Note that this is a glibc extension and not part of the C standard.



Answered By - Tom Karzes
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing