Clang Analyzer – A Great Cross-Platform C Static Analyzer

Clang Analyzer is a Static Code Analyzer for C and Objective-C.

Why it’s great:
1. It works on Mac, and Linux.
2. Running it is as easy as:

scan-build -V gcc -o prog prog.c

or

scan-build -V make

3. It gives great looking HTML reports.

4. You can easily report all or part of the errors as bugs:


Note (If you’re using Xcode):
Clang is built-in Xcode as of version 3.2. Run “Build and Analyze” to analyze your programs.


Define A Macro In C With A Variable Number Of Arguments

Say you want to wrap a function like printf() (which receives a variable number of arguments) with a macro. This is how to do it:


#define PRINT_DEBUG(fmt, args...)  printf("DBG:"fmt, ##args)

That is, declare them as args… and use them with ##args.

Note: The word args has nothing special, you could similarly use somethingelse… and ##somethingelse. Just in case you were wondering ;-)