A
ais523
I've been wondering about the compatibility of pointers to signed,
unsigned and plain char, and it's not clear to me how interchangeable
they are. Is the following portable?
int main(int argc, unsigned char** argv)
I suspect this would work on most implementations, but I'm not sure how
portable it is. According to a C89 draft, 'A pointer to void shall have
the same representation and alignment requirements as a pointer to a
character type. Other pointer types need not have the same
representation or alignment requirements.'; does this mean that void*
must have the same representation as all three pointer-to-character
types, or at least one of them, or plain char* specifically? This
section might imply that the representation of unsigned char* is the
same as that of char* (as they're both equal to void*), but I'm having
problems working it out. I can't even figure out whether int (*)(int,
char**) (the type of main normally) is compatible with int (*)(int,
unsigned char**) (the declared type here), and whether that would make
the declaration valid. I understand that the need to actually do this
would be limited in practice, but I'm interested in the theory.
unsigned and plain char, and it's not clear to me how interchangeable
they are. Is the following portable?
int main(int argc, unsigned char** argv)
I suspect this would work on most implementations, but I'm not sure how
portable it is. According to a C89 draft, 'A pointer to void shall have
the same representation and alignment requirements as a pointer to a
character type. Other pointer types need not have the same
representation or alignment requirements.'; does this mean that void*
must have the same representation as all three pointer-to-character
types, or at least one of them, or plain char* specifically? This
section might imply that the representation of unsigned char* is the
same as that of char* (as they're both equal to void*), but I'm having
problems working it out. I can't even figure out whether int (*)(int,
char**) (the type of main normally) is compatible with int (*)(int,
unsigned char**) (the declared type here), and whether that would make
the declaration valid. I understand that the need to actually do this
would be limited in practice, but I'm interested in the theory.