|
|
|
|
|
by jamessu
3723 days ago
|
|
His point was that you aren't interpreting the `const' the same way the compiler does. To the compiler, this: const int *a;
a = NULL; // perfectly OK
*a = 0; // does not compile
Is a pointer to a constant int, not a constant pointer to an int.You're probably confusing it with this: int *const a;
a = NULL; // does not compile
*a = 0; // perfectly OK
Which is a constant pointer to a regular int.Of course you can combine both as follows: const int *const a;
a = NULL; // does not compile
*a = 0; // does not compile
Which is a constant pointer to a constant int (which, of course, makes no sense at all in this case since 'a' is uninitialized and cannot be initialized without an unsafe cast, but it's a perfectly valid statement in C). |
|