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)
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With