Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #76715

Re: sizeof on an uninitialized pointer to a VLA

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: sizeof on an uninitialized pointer to a VLA
Date 2015-11-21 16:35 +1300
Message-ID <dba734FjpqnU6@mid.individual.net> (permalink)
References <5e03af2c-3c3e-4432-bf5a-000867e5febb@googlegroups.com> <n2ljik$iqo$1@dont-email.me> <ln610wevm8.fsf@kst-u.example.com> <87mvu8rbor.fsf@bsb.me.uk> <lnsi40axv9.fsf@kst-u.example.com>

Show all headers | View raw


Keith Thompson wrote:
> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>
>> But, as I am sure you know, the wording in the standard goes further.
>> If we replace *arr with arr[0] but with the 0 being produced by a
>> function call:
>>
>>    sizeof arr[f()]
>>
>> then the wording says that f must be called.  gcc obliges but clang does
>> not.  (No implementation is required to go any further and actually
>> access the as yet non-existent array, but the standard, as worded,
>> implies that the above, and the original, are undefined.)
>
> Interesting point.  Here's an example:
>
>      #include <stdio.h>
>
>      int zero(void) {
>          puts("zero()");
>          return 0;
>      }
>
>      int main(void) {
>          int n = 10;
>          char vla[n][n];
>          printf("sizeof vla[zero()] = %zu\n", sizeof vla[zero()]);
>      }
>
> The output using every version of gcc and clang I've tried is:
>
>      zero()
>      sizeof vla[zero()] = 10
>
> The sizeof computation is correct, but it *could* have been determined
> without calling the function.  As far as I can tell, the value returned
> by the call to zero() can have no effect on the result of the sizeof
> computation.

Is this a case of the observer effect?

I tired you code with Sun c99 and the whether the puts() line was there 
or not, the immediate value 10 was pushed.

-- 
Ian Collins

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

sizeof on an uninitialized pointer to a VLA John Bode <jfbode1029@gmail.com> - 2015-11-19 11:39 -0800
  Re: sizeof on an uninitialized pointer to a VLA supercat@casperkitty.com - 2015-11-19 12:09 -0800
  Re: sizeof on an uninitialized pointer to a VLA "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2015-11-19 21:40 +0000
    Re: sizeof on an uninitialized pointer to a VLA supercat@casperkitty.com - 2015-11-19 13:50 -0800
  Re: sizeof on an uninitialized pointer to a VLA James Kuyper <jameskuyper@verizon.net> - 2015-11-19 17:50 -0500
    Re: sizeof on an uninitialized pointer to a VLA supercat@casperkitty.com - 2015-11-19 15:31 -0800
    Re: sizeof on an uninitialized pointer to a VLA Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-20 01:09 +0000
      Re: sizeof on an uninitialized pointer to a VLA supercat@casperkitty.com - 2015-11-19 19:10 -0800
    Re: sizeof on an uninitialized pointer to a VLA Keith Thompson <kst-u@mib.org> - 2015-11-20 03:52 -0800
      Re: sizeof on an uninitialized pointer to a VLA Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-20 14:24 +0000
        Re: sizeof on an uninitialized pointer to a VLA supercat@casperkitty.com - 2015-11-20 10:25 -0800
        Re: sizeof on an uninitialized pointer to a VLA Keith Thompson <kst-u@mib.org> - 2015-11-20 18:29 -0800
          Re: sizeof on an uninitialized pointer to a VLA Ian Collins <ian-news@hotmail.com> - 2015-11-21 16:35 +1300
            Re: sizeof on an uninitialized pointer to a VLA Keith Thompson <kst-u@mib.org> - 2015-11-20 20:24 -0800
              Re: sizeof on an uninitialized pointer to a VLA Ian Collins <ian-news@hotmail.com> - 2015-11-21 17:38 +1300
                Re: sizeof on an uninitialized pointer to a VLA Keith Thompson <kst-u@mib.org> - 2015-11-20 21:08 -0800
          Re: sizeof on an uninitialized pointer to a VLA Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-21 10:46 +0000
            Re: sizeof on an uninitialized pointer to a VLA Keith Thompson <kst-u@mib.org> - 2015-11-21 03:26 -0800
              Re: sizeof on an uninitialized pointer to a VLA Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-21 12:46 +0000
                Re: sizeof on an uninitialized pointer to a VLA Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-21 14:01 +0000
              Re: sizeof on an uninitialized pointer to a VLA supercat@casperkitty.com - 2015-11-21 09:02 -0800
                Re: sizeof on an uninitialized pointer to a VLA Keith Thompson <kst-u@mib.org> - 2015-11-21 12:09 -0800

csiph-web