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


Groups > comp.lang.c > #76544 > unrolled thread

sizeof on an uninitialized pointer to a VLA

Started byJohn Bode <jfbode1029@gmail.com>
First post2015-11-19 11:39 -0800
Last post2015-11-21 12:09 -0800
Articles 2 on this page of 22 — 7 participants

Back to article view | Back to comp.lang.c


Contents

  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

Page 2 of 2 — ← Prev page 1 [2]


#76781

Fromsupercat@casperkitty.com
Date2015-11-21 09:02 -0800
Message-ID<81b2f3fc-c570-4daf-850b-237640f1fd22@googlegroups.com>
In reply to#76753
On Saturday, November 21, 2015 at 5:27:02 AM UTC-6, Keith Thompson wrote:
> 2. sizeof ( vla_type )
>    Not a constant expression.  Any expressions that are part of the type
>    name are evaluated

What if one has a VLA of pointers to a VLA type?  Would expressions forming
part of the name of the thing being pointed to be evaluated?

[toc] | [prev] | [next] | [standalone]


#76798

FromKeith Thompson <kst-u@mib.org>
Date2015-11-21 12:09 -0800
Message-ID<lnd1v36rnf.fsf@kst-u.example.com>
In reply to#76781
supercat@casperkitty.com writes:
> On Saturday, November 21, 2015 at 5:27:02 AM UTC-6, Keith Thompson wrote:
>> 2. sizeof ( vla_type )
>>    Not a constant expression.  Any expressions that are part of the type
>>    name are evaluated
>
> What if one has a VLA of pointers to a VLA type?  Would expressions forming
> part of the name of the thing being pointed to be evaluated?

Good question.  A concrete example:

    #include <stdio.h>

    int five(void) {
        puts("five()");
        return 5;
    }

    int six(void) {
        puts("six()");
        return 6;
    }

    int main(void) {
        printf("%zu\n", sizeof (char(*[five()])[six()]));
    }

On my system (where pointers are 8 bytes), the result of the
sizeof expression is 40, and both five() and six() are called.
The call to six() is not necessary to determine the result of the
sizeof expression.

(I'm not sure whether it's possible for the size to vary depending
on the value returned by six().)

I suggest that all expressions that are part of the type name should
be evaluated, just for the sake of keeping the description simple.
The standard could, I suppose, specify which expressions are needed
to determine the size and which are not, but it would be complex,
potentially ambiguous, and not worth the effort.  I could live
with it being unspecified if that would make things easier for
some compilers.

If I wanted to do something similar to the above in real-world
code, I would almost certainly define a typedef, so the issue
wouldn't arise:

    typedef char(*funky_array[five()])[six()];
    printf("%zu\n", sizeof (funky_array));

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.c


csiph-web