Re: [PATCH][resent] drivers/sound/ad1848.c fixes "cast to pointer from integer of different size"-wa

Stefan Monnier (monnier+lists/linux/kernel/news/@tequila.cs.yale.edu)
16 Nov 1998 10:13:07 -0500


>>>>> "Matthias" == Matthias Welwarsky <matze@stud.fbi.fh-darmstadt.de> writes:
> this fixes a compiler warning (and a possible bug) in ad1848.c by
> changing two variables from int to long, when compiled on architectures
> where sizeof(void *) != sizeof(int). The patch is relative 2.1.129-pre1.
> Don't know if this is really a problem in this context but I learned to
> be picky about this special warning since I own that Alpha ;-)

Looking at the code, it seems that dev_no and friends are really ints.
They are defined by the return value of sound_install_audiodrv (defined as
returning int) and used in array indexing (good hint that they should be rather
small integers). The reason for the warning is that this int is passed to
request_irq which expects a void* (most likely an argument that request_irq
never uses directly but rather stores somewhere and passes verbatim to the
interrupt handler. A poor man's closure, bascially).
So all what the code relies on is not `(foo*)(int)(foo*)x == (foo*)x' but
`(int)(void*)(int)x == (int)x' which is the case pretty much everywhere
(I'm not sure what ANSI C has to say about it, though).

Stefan

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/