Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of()

2017-05-23 Thread Ian Abbott
On 23/05/17 14:23, Ian Abbott wrote: On 23/05/17 13:02, Ian Abbott wrote: On 23/05/17 12:24, Peter Zijlstra wrote: On Tue, May 23, 2017 at 11:32:02AM +0100, Ian Abbott wrote: #define container_of(ptr, type, member) (\ _Static_assert(__builtin_types_compatible_p(

Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of()

2017-05-23 Thread Ian Abbott
On 23/05/17 14:23, Ian Abbott wrote: On 23/05/17 13:02, Ian Abbott wrote: On 23/05/17 12:24, Peter Zijlstra wrote: On Tue, May 23, 2017 at 11:32:02AM +0100, Ian Abbott wrote: #define container_of(ptr, type, member) (\ _Static_assert(__builtin_types_compatible_p(

Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of()

2017-05-23 Thread Ian Abbott
On 23/05/17 13:02, Ian Abbott wrote: On 23/05/17 12:24, Peter Zijlstra wrote: On Tue, May 23, 2017 at 11:32:02AM +0100, Ian Abbott wrote: #define container_of(ptr, type, member) (\ _Static_assert(__builtin_types_compatible_p(\ typeof(*ptr), typeof(

Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of()

2017-05-23 Thread Ian Abbott
On 23/05/17 13:02, Ian Abbott wrote: On 23/05/17 12:24, Peter Zijlstra wrote: On Tue, May 23, 2017 at 11:32:02AM +0100, Ian Abbott wrote: #define container_of(ptr, type, member) (\ _Static_assert(__builtin_types_compatible_p(\ typeof(*ptr), typeof(

Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of()

2017-05-23 Thread Ian Abbott
On 23/05/17 12:24, Peter Zijlstra wrote: On Tue, May 23, 2017 at 11:32:02AM +0100, Ian Abbott wrote: #define container_of(ptr, type, member) ( \ _Static_assert(__builtin_types_compatible_p(\ typeof(*ptr), typeof( ((type

Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of()

2017-05-23 Thread Ian Abbott
On 23/05/17 12:24, Peter Zijlstra wrote: On Tue, May 23, 2017 at 11:32:02AM +0100, Ian Abbott wrote: #define container_of(ptr, type, member) ( \ _Static_assert(__builtin_types_compatible_p(\ typeof(*ptr), typeof( ((type

Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of()

2017-05-23 Thread Peter Zijlstra
On Tue, May 23, 2017 at 11:32:02AM +0100, Ian Abbott wrote: > > #define container_of(ptr, type, member) ( \ > > _Static_assert(__builtin_types_compatible_p(\ > > typeof(*ptr), typeof( ((type *)0)->member )), "WUT"), \ > > ((type

Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of()

2017-05-23 Thread Peter Zijlstra
On Tue, May 23, 2017 at 11:32:02AM +0100, Ian Abbott wrote: > > #define container_of(ptr, type, member) ( \ > > _Static_assert(__builtin_types_compatible_p(\ > > typeof(*ptr), typeof( ((type *)0)->member )), "WUT"), \ > > ((type

Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of()

2017-05-23 Thread Ian Abbott
On 22/05/17 18:58, Michal Nazarewicz wrote: On Mon, May 22 2017, Ian Abbott wrote: If the first parameter of container_of() is a pointer to a non-const-qualified array type (and the third parameter names a non-const-qualified array member), the local variable __mptr will be defined with a

Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of()

2017-05-23 Thread Ian Abbott
On 22/05/17 18:58, Michal Nazarewicz wrote: On Mon, May 22 2017, Ian Abbott wrote: If the first parameter of container_of() is a pointer to a non-const-qualified array type (and the third parameter names a non-const-qualified array member), the local variable __mptr will be defined with a

Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of()

2017-05-22 Thread Michal Nazarewicz
On Mon, May 22 2017, Ian Abbott wrote: > If the first parameter of container_of() is a pointer to a > non-const-qualified array type (and the third parameter names a > non-const-qualified array member), the local variable __mptr will be > defined with a const-qualified array type. In ISO C, these

Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of()

2017-05-22 Thread Michal Nazarewicz
On Mon, May 22 2017, Ian Abbott wrote: > If the first parameter of container_of() is a pointer to a > non-const-qualified array type (and the third parameter names a > non-const-qualified array member), the local variable __mptr will be > defined with a const-qualified array type. In ISO C, these

[PATCH v2] kernel.h: handle pointers to arrays better in container_of()

2017-05-22 Thread Ian Abbott
If the first parameter of container_of() is a pointer to a non-const-qualified array type (and the third parameter names a non-const-qualified array member), the local variable __mptr will be defined with a const-qualified array type. In ISO C, these types are incompatible. They work as expected

[PATCH v2] kernel.h: handle pointers to arrays better in container_of()

2017-05-22 Thread Ian Abbott
If the first parameter of container_of() is a pointer to a non-const-qualified array type (and the third parameter names a non-const-qualified array member), the local variable __mptr will be defined with a const-qualified array type. In ISO C, these types are incompatible. They work as expected