Skip to content

Instantly share code, notes, and snippets.

@lierdakil
Last active February 7, 2019 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lierdakil/fcbcf9264ef10a2d0793574a6e66033a to your computer and use it in GitHub Desktop.
Save lierdakil/fcbcf9264ef10a2d0793574a6e66033a to your computer and use it in GitHub Desktop.
An example of messy const-correctness in C
struct bar { int foo; };
const struct bar fizz = { 10 };
void baz(struct bar * a) {
a->foo = 30;
}
int main() {
//fizz.foo = 20; // does not compile
baz(&fizz); // complies with warnings; WILL segfault!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment