i using visual studio 2015 c compiler , find lacks of warnings.
example code compile without warning or error (with -wall
option):
#include<stdlib.h> int main(void) { int = 2; free(&i); // compiler should tell me "you trying free not on heap". return 0; }
there lot of things causes crash or/and undefined behavior not detected -w4
or -wall
, is there other options can use warned these mistakes?
know use compiler, heard 1 comes visual studio better when targeting windows platform.
using compiler generate warnings, is, correctly point out not complete detection of undefined behavior.
turning on optimizations strangely improves compilers reporting. spots variables have not been set (value tracking) , unneeded values.
to go further compiler, static analysis tools such coverity , pc-lint stronger analysis. however, these products falsy, , highlight issues correct, misunderstand, , still miss undefined behavior.
particularly if cross-platform compiling, have more relaxed attitude compiler's warnings (clean gcc , vs difficult, , may damage code) , treat static analysis tool code-reviewer. when suggests failure, treat respect, assume have mis-understood code.
i had copy of pc-lint hanging around , got this...
--- module: file.c (c) _ free(&i); file.c(7) : warning 424: inappropriate deallocation (free) 'auto' data ---
Comments
Post a Comment