Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Clang warn me when I use non-standard functions provided by the GNU C Library?

Tags:

c

clang

I am writing a C program on OS X and compiling it with clang. I am quite new to C and I have come to understand that some functions like getline() are useful but non-standard. I would like to be able to compile the program on a system where the GNU C Library is not available. Not knowing exactly what functions are non-standard, I am hoping there is a command-line switch for clang to warn me whenever I use such functions. Is there?

Output from clang --version:

Apple LLVM version 5.1 (clang-503.0.40)

like image 728
Michiel van Oosterhout Avatar asked Dec 17 '25 11:12

Michiel van Oosterhout


2 Answers

You can use feature test macros (see also: XSH 2.2.1 POSIX.1 Symbols) to request visibility of only a particular set of standard interfaces. In particular,

-D_XOPEN_SOURCE=600

on the command line or

#define _XOPEN_SOURCE 600

should expose POSIX base plus the XSI option for the outdated 2001 version of POSIX (the latest OSX supports). If you want just base, without XSI, define _POSIX_C_SOURCE to 200112L.

like image 161
R.. GitHub STOP HELPING ICE Avatar answered Dec 19 '25 07:12

R.. GitHub STOP HELPING ICE


There is no command line switch to say 'tell me if this is nonstandard'. The most common way of developing code that needs to be compatible across a variety of platforms is the gnu autotools suite, which gives you a configuration script which checks for various functionality and allows you to code around it, or have the system give up before going any further.

like image 32
Petesh Avatar answered Dec 19 '25 07:12

Petesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!