Date: Mon, 29 Dec 2008 11:25:28 +0100 From: Hans Petter Selasky <hselasky@c2i.net> To: Dag-Erling =?utf-8?q?Sm=C3=B8rgrav?= <des@des.no> Cc: freebsd-current@freebsd.org, current@freebsd.org, Alfred Perlstein <alfred@freebsd.org> Subject: Re: HEADSUP usb2 (usb4bsd) to become default in 2 weeks. Message-ID: <200812291125.30222.hselasky@c2i.net> In-Reply-To: <86d4fb72se.fsf@ds4.des.no> References: <20081222214010.GA18389@elvis.mu.org> <200812231736.29198.hselasky@c2i.net> <86d4fb72se.fsf@ds4.des.no>
next in thread | previous in thread | raw e-mail | index | archive | help
On Monday 29 December 2008, Dag-Erling Sm=C3=B8rgrav wrote: > Hans Petter Selasky <hselasky@c2i.net> writes: > > LIBUSB20_ADD_BYTES() is a hack to circumvent things like un-constifying > > and making a byte increment to any pointer type. USB descriptors are > > byte-packed. I have tested the macro with several kinds of compilers and > > none have complained yet. > > 1) if you need to de-constify, your API is broken. The following function is a candidate for de-constifying. You have a data=20 pointer there which is read or write, and to be able to transfer constant=20 data you need to do a deconst before passing the pointer to this function. usb2_do_request_flags(struct usb2_device *udev, struct mtx *mtx, struct usb2_device_request *req, void *data, uint32_t flags, uint16_t *actlen, uint32_t timeout) Deconstifying is not illegal in C using standard pointer arithmetics. (void *)((const uint8_t *)(ptr) - (const uint8_t *)0) > > 2) just because the compiler doesn't know it's wrong doesn't mean it > isn't. > > 3) the pointer magic you do in (for instance) libusb20_me_encode() and > libusb20_me_decode() won't work on strict-alignment platforms. > Yes, it will, because all addresses are aligned before they get casted. =2D-HPS
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200812291125.30222.hselasky>