Re: [PATCH] powerpc/usb: use unsigned long to type cast an address of ioremap

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Arithmetic on 'void *' should not be done. I know some versions of
gcc allow it (provided some warning level/option is enabled) but
that doesn't mean it is valid.

All relevant GCC versions support it (going back to 2.x at least).
It is _always_ allowed, whatever compiler options you use; -pedantic
or -Wpointer-arith will warn (which you can upgrade to an error).

The Linux kernel is not built with these warnings enabled.

A char* is incorrect because a char could be more
than one byte, in theory.

It is somewhat difficult to untangle the standard, but
sizeof (char) is defined to be one.

A char takes exactly one byte.  A byte could be more than eight bits,
of course.

In GCC, sizeof(void) is 1 as well.

Of course, the C language doesn't actually require that
you can converts between pointers to different types in
any well-defined manner.

It does actually, see 6.3.2.3/7.  You can convert any pointer to object
to a pointer to a different object type, as long as it is properly aligned.
You cannot in general access the object as that new type of course, but
it is perfectly well-defined; in particular, you can convert it back to
the original type and get the same value again, and you can walk consecutive
bytes of the object by using a pointer to character type.


Segher

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux