How can I make this GCC warning an error?

I’m not sure what the correct warning is, but once you’ve found it, you can change its disposition with the following (using ‘format’ as the example): #pragma GCC diagnostic error “-Wformat” Or as strager points out: gcc -Werror=format … I’ve checked the gcc source for this and this specific warning cannot be disabled via command … Read more

Is there a way to get warned about unused functions?

Caolan Mc Namara, a LibreOffice developer, has made a small tool to detect this type of thing in LibreOffice source code. They had around thousands functions & methods unused in LibreOffice. His tool is a key element for removing them. It’s called callcatcher. It can collect functions/methods defined and subtract called/referenced It works directly on … Read more

Is there a GCC option to warn about writing `this-field` instead of `this->field`?

This particular issue is detected by cppcheck: $ cppcheck –enable=all this-minus-bool.cxx Checking this-minus-bool.cxx… [this-minus-bool.cxx:7]: (warning) Suspicious pointer subtraction. Did you intend to write ‘->’? (information) Cppcheck cannot find all the include files (use –check-config for details) This was with no include path given. If I add -I /usr/include/c++/4.8/, the issue is still detected: Checking this-minus-bool.cxx… … Read more

Compile and run program without main() in C

Let’s have a look at the generated assembly of your program: .LC0: .string “Hello World…” .LC1: .string “Successfully run without main…” nomain: push rbp mov rbp, rsp mov edi, OFFSET FLAT:.LC0 call puts mov edi, OFFSET FLAT:.LC1 call puts nop pop rbp ret Note the ret statement. Your program’s entry point is determined to be … Read more