From owner-freebsd-current Sun Feb 21 2:16:38 1999 Delivered-To: freebsd-current@freebsd.org Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.26.10.9]) by hub.freebsd.org (Postfix) with ESMTP id D48FA116AE for ; Sun, 21 Feb 1999 02:15:59 -0800 (PST) (envelope-from bde@godzilla.zeta.org.au) Received: (from bde@localhost) by godzilla.zeta.org.au (8.8.7/8.8.7) id QAA13128; Sun, 21 Feb 1999 16:37:20 +1100 Date: Sun, 21 Feb 1999 16:37:20 +1100 From: Bruce Evans Message-Id: <199902210537.QAA13128@godzilla.zeta.org.au> To: freebsd-current@FreeBSD.ORG, hibma@skylink.it Subject: Re: const char * Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG >../../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 (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 majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message