F
FtM
Hello.
I was updating some code trying to enforce the use of "const"
modifiers, and I came up with some strange doubts.
First of all:
If I have a:
const void *p;
I can read and write the data pointed by p, but I cannot modify the
value of the pointer itself, while with a:
void * const p;
I can modify the pointer value but not the data it points to.
So a:
const void * const p;
gives me a completely "locked" pointer.
Is it right?
If I am right, why some standard functions have inconsistent
prototypes? For example, memcpy:
void *memcpy(void *s1, const void *s2, size_t n);
shouldn't it be:
void *memcpy(const void *s1, const void *const s2, size_t n);
?
Am I missing something?
Thank you for your answers!
I was updating some code trying to enforce the use of "const"
modifiers, and I came up with some strange doubts.
First of all:
If I have a:
const void *p;
I can read and write the data pointed by p, but I cannot modify the
value of the pointer itself, while with a:
void * const p;
I can modify the pointer value but not the data it points to.
So a:
const void * const p;
gives me a completely "locked" pointer.
Is it right?
If I am right, why some standard functions have inconsistent
prototypes? For example, memcpy:
void *memcpy(void *s1, const void *s2, size_t n);
shouldn't it be:
void *memcpy(const void *s1, const void *const s2, size_t n);
?
Am I missing something?
Thank you for your answers!