N
Noob
Hello,
Is the following code valid:
static void foo(unsigned char *buf)
{
int i;
for (i = 0; i < 16; ++i) buf = i;
}
void bar(void)
{
unsigned long arr[4];
foo(arr);
}
The compiler points out that (unsigned long *) is not
compatible with (unsigned char *).
So I cast to the expected type:
void bar(void)
{
unsigned long arr[4];
foo((unsigned char *)arr);
}
I think it is allowed to cast to (unsigned char *)
but I don't remember if it's allowed only to inspect
(read) the values, or also to set them. Also the fact
the "real" type is unsigned means there are no trap
representations, right?
Regards.
Is the following code valid:
static void foo(unsigned char *buf)
{
int i;
for (i = 0; i < 16; ++i) buf = i;
}
void bar(void)
{
unsigned long arr[4];
foo(arr);
}
The compiler points out that (unsigned long *) is not
compatible with (unsigned char *).
So I cast to the expected type:
void bar(void)
{
unsigned long arr[4];
foo((unsigned char *)arr);
}
I think it is allowed to cast to (unsigned char *)
but I don't remember if it's allowed only to inspect
(read) the values, or also to set them. Also the fact
the "real" type is unsigned means there are no trap
representations, right?
Regards.