Re: [PATCH 7/16] Let void have sizeof 1

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

 



On Wed, Dec 24, 2008 at 1:59 PM, David Given <dg@xxxxxxxxxxx> wrote:
> The thing is, sizeof(void) is *not* 1. sizeof(void) is *illegal*. It
> just happens that gcc, as a platform-specific extension, treats
> sizeof(void) as 1 by default.

Exactly. I am unhappy about that patch as well.
Sparse internally use symbol->bit_size == 0 to determine uncompleted type.
Thanks this change. Now is_byte_type() will return true for void type as well.

> As a linter, sparse really ought not to be encouraging non-portable
> behaviour. Admittedly, there's so much stuff in the kernel source that's
> gcc-specific that it's probably not going to be possible to make it
> build on anything else, but it should still warn people about it unless
> specifically told otherwise --- it's bad practice, and may be indicative
> of further problems elsewhere, and as such is worth a diagnostic.

I don't see the kernel directly use sizeof(void). Most of the place is
using (void*) pointer + offset. It is not portable. But it is probably not
worthy while to fix. Convert the void* to char*, add offset, convert it back
to void* is pretty annoying as well. If we really want to make it clean, maybe
we can use a macro or inline functions. Again, probably not worth the effort.

But legitimize sizeof(void) == 1 is a different story. That I feel is just
plain wrong.

Even gcc is self contradicting regarding the size of void.
Compiling "void i;" will give you:
/tmp/void.c:1: error: storage size of 'i' isn't known

I saw Josh just merge the sizeof(void) patch. Oh well.

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

[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux