>../../dev/usb/ukbd.c: In function `ukbd_detach':
>../../dev/usb/ukbd.c:373: warning: cast discards `const' from pointer
>target type
>...
>It is a consequence of the following type definition:
>
>(sys/bus_private.h)
>struct device {
>...
>    const char*         desc;   /* driver specific description */
>...
>}
>
>One problem I have is that a string like that might be produced by
>concatenating a few strings together.  In the case of USB the desc is
>the string returned by the device. At attach the string is created and
>malloc()-ed, at detach free()-ed. 

At the <sys/bus*.h> (bus) level, `desc' is just a string.  It is const
mainly so that callers can pass a literal string to device_set_desc()
without getting a warning from -Wcast-qual.  Unfortunately, this prevents
the bus level from helping you keep track of how the string was created.

The warning could be avoided using a table of the original (non-const)
addresses of the (malloc()ed) strings passed to device_set_desc().
This is a bit much to avoid a harmless warning, but you would need to
do it if not all strings were malloc()ed.

The warning can be avoided by (ab)using a variant union.  I plan to use
a suitably macroised version of this to fix warnings for library functions.

Bruce


To Unsubscribe: send mail to majord...@freebsd.org
with "unsubscribe freebsd-current" in the body of the message

Reply via email to