Created
April 19, 2012 16:53
-
-
Save k0001/2422264 to your computer and use it in GitHub Desktop.
C const rules cheat shit
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
typedef struct { | |
int a; | |
const int b; | |
} thing_t; | |
int main(int argc, char *argv[]) | |
{ | |
thing_t t1 = { .a = 1, .b = 2 }; | |
t1.a = 90; | |
// t1.b = 90; // NO! | |
const thing_t t2 = { .a = 3, .b = 4 }; | |
// t2.a = 90; // NO! | |
// t2.b = 90; // DOUBLE NO! | |
thing_t * const p0 = &t1; | |
p0->a = 90; | |
// p0->b = 90; // NO! | |
// p0 = &t1; // NO! | |
const thing_t * | |
// p1->a = 90; // NO! | |
// p1->b = 90; // DOUBLE NO! | |
p1 = &t1; | |
const thing_t * const p2 = &t1; | |
// p2->a = 90; // NO! | |
// p2->b = 90; // DOUBLE NO! | |
// p2 = &t1; // NO! | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment