Last active
February 7, 2019 12:29
-
-
Save lierdakil/fcbcf9264ef10a2d0793574a6e66033a to your computer and use it in GitHub Desktop.
An example of messy const-correctness in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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