Ask HN: Resources for First Time Acquisitions
2 pointsby 0x090 comments
struct { int a; int b; } f() {
return (typeof(f())){1,2};
}
int g() {
typeof(f()) x = f();
return x.a + x.b;
}
edit: though I suppose this just pushes the problem onto callers, since every function that does this now has a distinct return type that can only be referenced using typeof(yourfn). void *x = malloc(...);
free(x);
if(x); // undefined behavior
Note that this isn't about dereferencing x after free, which is understandably not valid. Rather the standard specifies that any use of the pointer's value itself is undefined after being used as an argument to free, even though syntactically free could not have altered that. clang --analyze --analyzer-output text ...
Will print the entire analysis tree in the same format as regular diagnostics. void f(char (*n)[255]);
char array[6];
f(&array);
warns of "incompatible pointer types passing 'char (* )[6]' to parameter of type 'char (* )[255]'"
You might consider the int_fastN_t types a sort of spiritual successor to this with fewer downsides since they purposefully guarantee a minimum width.