lkml.org 
[lkml]   [2022]   [Feb]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] container_of.h: make container_of const-aware
On Thu, 10 Feb 2022 20:04:34 +0300 Dmitry Baryshkov <dmitry.baryshkov@linaro.org> wrote:

> container_of() macro has one major drawback. It does not check whether
> the passed ptr has a const pointer, the result will always be a
> non-const pointer. Use a _Generic() construct (supported since gcc 4.9
> and Clang 3.0) to teach container_of that if converting a const pointer,
> the returned pointer should also have the const modifier.
>

Nice idea, but my x86_64 allnoconfig build explodes with zillions of
warnings.

In file included from ./include/linux/list.h:5,
from ./include/linux/module.h:12,
from init/do_mounts.c:2:
./include/net/sock.h: In function 'sk_entry':
./include/linux/container_of.h:17:42: warning: return discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]

\
 
 \ /
  Last update: 2022-02-11 23:06    [W:0.057 / U:0.712 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site