RE: [PATCH v2 1/2] system_data_types.7: Add 'void *'

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

 



From: Alejandro Colomar
> Sent: 02 October 2020 09:25
>  > For 'void *' you should also mention that one cannot use arithmetic on
>  > void * pointers, so they're special in that way too.
> 
> Good suggestion!

Except that is a gcc extension that is allowed in the kernel.

>  > Also, you should
>  > warn that because one can convert from any pointer type to void * and
>  > then to any other pointer type, it's a deliberate hole in C's
>  > type-checking.
> 
> Also good.  I'll talk about generic function parameters for this.

That isn't what the C standard says at all.
What is says is that you can cast any data pointer to 'void *'
and then cast it back to the same type.

This matters because the compiler will 'remember' structure
alignment through 'void *' casts.
So you can't use memcpy() to copy from a potentially misaligned
(typed) pointer.

'void *' should only be used for structures that are 'a sequence of bytes'.
(eg things that look a bit like read() or write()).

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)




[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux