GCC
Creating and using shared library
On Linux:
gcc -shared -fPIC foo.c -o foo.so export LD_PRELOAD=`pwd`/foo.so
If using relative path to specify shared library,
ld.so
will report error for can’t preload the specified library and ignore that error.On Mac OS X:
gcc -dynamiclib -undefined suppress -flat_namespace foo.c -o foo.dylib export DYLD_INSERT_LIBRARIES=`pwd`/foo.dylib
Also not the
DYLD_LIBRARY_PATH
environment variable. From Where is LD_PRELOAD under Mac OS X?dyld will look for the library in the specified location. If it does not exist, it will look in specific library paths specified in DYLD_LIBRARY_PATH. If the linking works and the library is able to match the symbols, the program will run, otherwise it will fail.
For more information about dynamic library on OS X, refer to my Mac notes.
List all pre-defined macros
From Stack Overflow, Using the following command
touch dummy
cpp -dM ./dummy
Runtime checks
-fmudflap
find pointer arithmetic errors during runtime-fstack-check
stack overflow protection-gnato
checks for overflows during integer operations
Extensions to C
Binary literals
Use the 0b
prefix:
int integer=0b10111001;