[lkml]   [2008]   [Apr]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH 7/7] asm-generic: suppress sparse warning in ioctl.h
On Fri, Apr 04, 2008 at 02:19:51AM +0100, Al Viro wrote:
> * no functions returning variably-modified type.

Note: *pointer* to function returning a variably-modified type is possible,
is variably-modified itself and as such can appear only in function and
the same "compiler will consider VLA compatible with any array that has
as compatible element, but if the size doesn't match it's on your head"
applies. IOW,

int a[2][2] = {{1, 2}, {3, 4}};

int (*f(void))[2] /* return a pointer to two-element array of int */
return &a[0];

int h(int n)
/* pointer to function that returns a pointer to n-element VLA of int */
int (*(*p)(void))[n];
/* OK if n is 2, undefined otherwise */
p = f;
return p()[1][1];

is fine and h(2) will give you 4, but if you ever do e.g. h(1), you are in
nasal daemon country. In reality h(1) will _probably_ give a[1][0], but
compiler has every right to silently produce a binary that'll wipe your disk
or do the same itself...

 \ /
  Last update: 2008-04-04 04:03    [W:0.065 / U:17.404 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site