lkml.org 
[lkml]   [2020]   [Oct]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [PATCH v2 1/2] system_data_types.7: Add 'void *'
Date
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)
\
 
 \ /
  Last update: 2020-10-02 11:11    [W:0.132 / U:1.196 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site