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


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

Dinamic array without malloc - Can be done?

Started by"Fernando D. Bozzo" <fdbozzo@gmail.com>
First post2017-01-15 08:45 -0800
Last post2017-01-30 05:21 -0800
Articles 20 on this page of 151 — 22 participants

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


Contents

  Dinamic array without malloc - Can be done? "Fernando D. Bozzo" <fdbozzo@gmail.com> - 2017-01-15 08:45 -0800
    Re: Dinamic array without malloc - Can be done? BartC <bc@freeuk.com> - 2017-01-15 16:53 +0000
      Re: Dinamic array without malloc - Can be done? fir <profesor.fir@gmail.com> - 2017-01-15 09:34 -0800
        Re: Dinamic array without malloc - Can be done? BartC <bc@freeuk.com> - 2017-01-17 21:09 +0000
          Re: Dinamic array without malloc - Can be done? fir <profesor.fir@gmail.com> - 2017-01-17 13:45 -0800
            Re: Dinamic array without malloc - Can be done? fir <profesor.fir@gmail.com> - 2017-01-17 14:09 -0800
            Re: Dinamic array without malloc - Can be done? BartC <bc@freeuk.com> - 2017-01-17 22:41 +0000
            Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-17 15:06 -0800
              Re: Dinamic array without malloc - Can be done? fir <profesor.fir@gmail.com> - 2017-01-17 16:49 -0800
              Re: Dinamic array without malloc - Can be done? Keith Thompson <kst-u@mib.org> - 2017-01-17 16:56 -0800
                Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-17 20:37 -0800
                  Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-18 09:38 +0100
                  Re: Dinamic array without malloc - Can be done? Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-31 08:49 -0800
                    Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-31 10:39 -0800
                      Re: Dinamic array without malloc - Can be done? luser droog <luser.droog@gmail.com> - 2017-01-31 10:55 -0800
                        Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-31 11:40 -0800
                      Re: Dinamic array without malloc - Can be done? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-01-31 10:57 -0800
                      Re: Dinamic array without malloc - Can be done? Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-03 23:06 -0800
      Re: Dinamic array without malloc - Can be done? "Fernando D. Bozzo" <fdbozzo@gmail.com> - 2017-01-15 10:42 -0800
        Re: Dinamic array without malloc - Can be done? BartC <bc@freeuk.com> - 2017-01-15 20:15 +0000
          Re: Dinamic array without malloc - Can be done? Keith Thompson <kst-u@mib.org> - 2017-01-15 12:43 -0800
          Re: Dinamic array without malloc - Can be done? "Fernando D. Bozzo" <fdbozzo@gmail.com> - 2017-01-15 15:08 -0800
    Re: Dinamic array without malloc - Can be done? "James R. Kuyper" <jameskuyper@verizon.net> - 2017-01-15 12:25 -0500
      Re: Dinamic array without malloc - Can be done? "Fernando D. Bozzo" <fdbozzo@gmail.com> - 2017-01-15 10:46 -0800
        Re: Dinamic array without malloc - Can be done? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-15 20:13 +0000
          Re: Dinamic array without malloc - Can be done? "Fernando D. Bozzo" <fdbozzo@gmail.com> - 2017-01-15 15:06 -0800
      Re: Dinamic array without malloc - Can be done? Keith Thompson <kst-u@mib.org> - 2017-01-15 12:46 -0800
        Re: Dinamic array without malloc - Can be done? "James R. Kuyper" <jameskuyper@verizon.net> - 2017-01-15 16:10 -0500
        Re: Dinamic array without malloc - Can be done? Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-15 20:37 -0800
          Re: Dinamic array without malloc - Can be done? Keith Thompson <kst-u@mib.org> - 2017-01-15 21:02 -0800
            Re: Dinamic array without malloc - Can be done? Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-30 04:23 -0800
          Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-16 09:05 +0100
            Re: Dinamic array without malloc - Can be done? Ian Collins <ian-news@hotmail.com> - 2017-01-16 21:16 +1300
              Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-16 09:48 +0100
    Re: Dinamic array without malloc - Can be done? fir <profesor.fir@gmail.com> - 2017-01-15 09:29 -0800
      Re: Dinamic array without malloc - Can be done? fir <profesor.fir@gmail.com> - 2017-01-15 09:37 -0800
      Re: Dinamic array without malloc - Can be done? fir <profesor.fir@gmail.com> - 2017-01-15 09:56 -0800
        Re: Dinamic array without malloc - Can be done? fir <profesor.fir@gmail.com> - 2017-01-15 10:34 -0800
      Re: Dinamic array without malloc - Can be done? "Fernando D. Bozzo" <fdbozzo@gmail.com> - 2017-01-15 10:48 -0800
        Re: Dinamic array without malloc - Can be done? fir <profesor.fir@gmail.com> - 2017-01-15 11:10 -0800
        Re: Dinamic array without malloc - Can be done? Jean-Marc Bourguet <jm@bourguet.org> - 2017-01-15 20:22 +0100
          Re: Dinamic array without malloc - Can be done? Chad <cdalten@gmail.com> - 2017-01-15 11:50 -0800
          Re: Dinamic array without malloc - Can be done? "Fernando D. Bozzo" <fdbozzo@gmail.com> - 2017-01-15 15:12 -0800
    Re: Dinamic array without malloc - Can be done? Richard Heathfield <rjh@cpax.org.uk> - 2017-01-15 17:50 +0000
      Re: Dinamic array without malloc - Can be done? "Fernando D. Bozzo" <fdbozzo@gmail.com> - 2017-01-15 10:38 -0800
        Re: Dinamic array without malloc - Can be done? Richard Heathfield <rjh@cpax.org.uk> - 2017-01-15 19:34 +0000
          Re: Dinamic array without malloc - Can be done? Keith Thompson <kst-u@mib.org> - 2017-01-15 12:51 -0800
            Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-15 13:10 -0800
              Re: Dinamic array without malloc - Can be done? Keith Thompson <kst-u@mib.org> - 2017-01-15 16:23 -0800
                Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-15 18:08 -0800
              Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-16 09:56 +0100
                Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-16 08:35 -0800
                  Re: Dinamic array without malloc - Can be done? "Chris M. Thomasson" <invalid@invalid.invalid> - 2017-01-16 11:07 -0800
                    Re: Dinamic array without malloc - Can be done? "Chris M. Thomasson" <invalid@invalid.invalid> - 2017-01-16 11:17 -0800
                      Re: Dinamic array without malloc - Can be done? Robert Wessel <robertwessel2@yahoo.com> - 2017-01-16 15:21 -0600
                        Re: Dinamic array without malloc - Can be done? "Chris M. Thomasson" <invalid@invalid.invalid> - 2017-01-31 22:22 -0800
                  Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-17 00:22 +0100
                    Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-16 16:23 -0800
                      Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-17 02:04 +0100
                        Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-16 17:27 -0800
                          Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-17 09:16 +0100
            Re: Dinamic array without malloc - Can be done? Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-15 20:32 -0800
            Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-16 10:02 +0100
              Re: Dinamic array without malloc - Can be done? Keith Thompson <kst-u@mib.org> - 2017-01-16 09:22 -0800
                Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-17 00:25 +0100
        Re: Dinamic array without malloc - Can be done? Barry Schwarz <schwarzb@dqel.com> - 2017-01-15 11:53 -0800
          Re: Dinamic array without malloc - Can be done? fir <profesor.fir@gmail.com> - 2017-01-15 12:22 -0800
          Re: Dinamic array without malloc - Can be done? "Fernando D. Bozzo" <fdbozzo@gmail.com> - 2017-01-15 15:32 -0800
            Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-15 16:01 -0800
              Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-16 10:19 +0100
                Re: Dinamic array without malloc - Can be done? BartC <bc@freeuk.com> - 2017-01-16 11:28 +0000
                  Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-16 14:29 +0100
                    Re: Dinamic array without malloc - Can be done? BartC <bc@freeuk.com> - 2017-01-16 15:41 +0000
                      Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-16 17:27 +0100
                    Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-16 07:56 -0800
                      Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-16 17:31 +0100
                        Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-16 08:48 -0800
                          Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-17 00:29 +0100
                  Re: Dinamic array without malloc - Can be done? "Chris M. Thomasson" <invalid@invalid.invalid> - 2017-01-16 11:25 -0800
                    Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-16 12:28 -0800
                      Re: Dinamic array without malloc - Can be done? "Chris M. Thomasson" <invalid@invalid.invalid> - 2017-01-16 12:38 -0800
            Re: Dinamic array without malloc - Can be done? Keith Thompson <kst-u@mib.org> - 2017-01-15 16:57 -0800
              Re: Dinamic array without malloc - Can be done? "Fernando D. Bozzo" <fdbozzo@gmail.com> - 2017-01-16 00:37 -0800
                Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-16 10:23 +0100
                  Re: Dinamic array without malloc - Can be done? "Fernando D. Bozzo" <fdbozzo@gmail.com> - 2017-01-16 01:35 -0800
                    Re: Dinamic array without malloc - Can be done? Keith Thompson <kst-u@mib.org> - 2017-01-16 09:15 -0800
            Re: Dinamic array without malloc - Can be done? BartC <bc@freeuk.com> - 2017-01-16 01:29 +0000
          Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-16 10:08 +0100
            Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-16 08:08 -0800
              Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-17 00:35 +0100
                Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-16 16:31 -0800
                  Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-17 09:27 +0100
                    Re: Dinamic array without malloc - Can be done? BartC <bc@freeuk.com> - 2017-01-17 12:11 +0000
                      Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-17 14:23 +0100
                      Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-17 05:38 -0800
                        Re: Dinamic array without malloc - Can be done? BartC <bc@freeuk.com> - 2017-01-17 14:17 +0000
                          Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-17 07:09 -0800
                    Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-17 05:14 -0800
                      Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-17 14:40 +0100
                        Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-17 06:41 -0800
                          Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-17 16:00 +0100
                            Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-17 07:45 -0800
                              Re: Dinamic array without malloc - Can be done? fir <profesor.fir@gmail.com> - 2017-01-17 08:18 -0800
                                Re: Dinamic array without malloc - Can be done? fir <profesor.fir@gmail.com> - 2017-01-17 08:27 -0800
                                  Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-17 09:29 -0800
                                Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-17 09:23 -0800
                                  Re: Dinamic array without malloc - Can be done? fir <profesor.fir@gmail.com> - 2017-01-17 10:35 -0800
                                    Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-17 12:41 -0800
                                      Re: Dinamic array without malloc - Can be done? fir <profesor.fir@gmail.com> - 2017-01-17 13:45 -0800
                            Re: Dinamic array without malloc - Can be done? Robert Wessel <robertwessel2@yahoo.com> - 2017-01-17 21:00 -0600
        Re: Dinamic array without malloc - Can be done? fir <profesor.fir@gmail.com> - 2017-01-15 11:55 -0800
        Re: Dinamic array without malloc - Can be done? Siri Cruise <chine.bleu@yahoo.com> - 2017-01-15 14:59 -0800
      Re: Dinamic array without malloc - Can be done? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-15 20:04 +0000
        Re: Dinamic array without malloc - Can be done? David Brown <david.brown@hesbynett.no> - 2017-01-15 21:33 +0100
          Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-15 13:00 -0800
            Re: Dinamic array without malloc - Can be done? Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-15 20:27 -0800
          Re: Dinamic array without malloc - Can be done? "James R. Kuyper" <jameskuyper@verizon.net> - 2017-01-15 16:34 -0500
            Re: Dinamic array without malloc - Can be done? "James R. Kuyper" <jameskuyper@verizon.net> - 2017-01-15 16:43 -0500
              Re: Dinamic array without malloc - Can be done? Keith Thompson <kst-u@mib.org> - 2017-01-15 16:17 -0800
                Re: Dinamic array without malloc - Can be done? Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-15 20:22 -0800
                  Re: Dinamic array without malloc - Can be done? Keith Thompson <kst-u@mib.org> - 2017-01-15 21:00 -0800
                    Re: Dinamic array without malloc - Can be done? Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-30 05:01 -0800
                      Re: Dinamic array without malloc - Can be done? Keith Thompson <kst-u@mib.org> - 2017-01-30 11:35 -0800
                        Re: Dinamic array without malloc - Can be done? Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-01 16:18 -0800
                          Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-02-01 16:37 -0800
                            Re: Dinamic array without malloc - Can be done? Robert Wessel <robertwessel2@yahoo.com> - 2017-02-01 23:21 -0600
                            Re: Dinamic array without malloc - Can be done? Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-02 00:27 -0800
                              Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-02-02 10:58 -0800
                                Re: Dinamic array without malloc - Can be done? Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-03 22:51 -0800
    Re: Dinamic array without malloc - Can be done? "Chris M. Thomasson" <invalid@invalid.invalid> - 2017-01-15 15:41 -0800
      Re: Dinamic array without malloc - Can be done? "Fernando D. Bozzo" <fdbozzo@gmail.com> - 2017-01-15 15:44 -0800
        Re: Dinamic array without malloc - Can be done? "Chris M. Thomasson" <invalid@invalid.invalid> - 2017-01-15 16:17 -0800
    Re: Dinamic array without malloc - Can be done? Alla _ <modelling.data@gmail.com> - 2017-01-16 01:47 -0800
      Re: Dinamic array without malloc - Can be done? "Fernando D. Bozzo" <fdbozzo@gmail.com> - 2017-01-16 01:50 -0800
        Re: Dinamic array without malloc - Can be done? Alla _ <modelling.data@gmail.com> - 2017-01-16 02:38 -0800
          Re: Dinamic array without malloc - Can be done? "Fernando D. Bozzo" <fdbozzo@gmail.com> - 2017-01-16 03:15 -0800
            Re: Dinamic array without malloc - Can be done? Alla _ <modelling.data@gmail.com> - 2017-01-16 03:40 -0800
              Re: Dinamic array without malloc - Can be done? "Fernando D. Bozzo" <fdbozzo@gmail.com> - 2017-01-16 04:21 -0800
            Re: Dinamic array without malloc - Can be done? Alla _ <modelling.data@gmail.com> - 2017-01-16 04:29 -0800
              Re: Dinamic array without malloc - Can be done? "Fernando D. Bozzo" <fdbozzo@gmail.com> - 2017-01-16 04:36 -0800
      Re: Dinamic array without malloc - Can be done? Richard Heathfield <rjh@cpax.org.uk> - 2017-01-16 11:36 +0000
        Re: Dinamic array without malloc - Can be done? Alla _ <modelling.data@gmail.com> - 2017-01-16 03:44 -0800
        Re: Dinamic array without malloc - Can be done? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-16 15:34 +0000
          Re: Dinamic array without malloc - Can be done? Richard Heathfield <rjh@cpax.org.uk> - 2017-01-16 16:01 +0000
    Re: Dinamic array without malloc - Can be done? John Bode <jfbode1029@gmail.com> - 2017-01-17 10:14 -0800
      Re: Dinamic array without malloc - Can be done? James Kuyper <jameskuyper@verizon.net> - 2017-01-17 13:21 -0500
        Re: Dinamic array without malloc - Can be done? John Bode <jfbode1029@gmail.com> - 2017-01-17 11:43 -0800
          Re: Dinamic array without malloc - Can be done? James Kuyper <jameskuyper@verizon.net> - 2017-01-17 15:07 -0500
        Re: Dinamic array without malloc - Can be done? supercat@casperkitty.com - 2017-01-17 12:24 -0800
      Re: Dinamic array without malloc - Can be done? "Fernando D. Bozzo" <fdbozzo@gmail.com> - 2017-01-17 10:24 -0800
      Re: Dinamic array without malloc - Can be done? Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-30 05:21 -0800

Page 2 of 8 — ← Prev page 1 [2] 3 4 5 6 7 8  Next page →


#101879

FromKeith Thompson <kst-u@mib.org>
Date2017-01-15 12:43 -0800
Message-ID<lnr344gikt.fsf@kst-u.example.com>
In reply to#101876
BartC <bc@freeuk.com> writes:
> On 15/01/2017 18:42, Fernando D. Bozzo wrote:
[...]
>>     myArray[0] = 'A';
>>     myArray[1] = '\0';
>
> This assumes that len is at least two. And below, that it is a least 4. 
> But len can be 0 or 1.

C does not permit array of length 0, though some compilers may support
them as an extension.  For a non-VLA, defining a 0-length array is a
constraint violation; for a VLA, it's undefined behavior (which a
compiler might warn about if it has enough information).

-- 
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] | [next] | [standalone]


#101890

From"Fernando D. Bozzo" <fdbozzo@gmail.com>
Date2017-01-15 15:08 -0800
Message-ID<9b488d27-903b-4006-908d-523306f47b5e@googlegroups.com>
In reply to#101876
El domingo, 15 de enero de 2017, 21:15:43 (UTC+1), Bart  escribió:
> On 15/01/2017 18:42, Fernando D. Bozzo wrote:
> > El domingo, 15 de enero de 2017, 17:53:57 (UTC+1), Bart  escribió:
> > <snip>
> >>
> >> It should work; did you put the code inside a function? Eg:
> >>
> >>   int main(void) {
> >>     int len=rand()+100;
> >>     char myArray[len];
> >>
> >>     printf("%d\n",(int)sizeof(myArray));
> 
> > Ok, I've re-tested again (last time was 3-4 days ago and I can't remember how exactly I did) and it works:
> >
> >
> >     int len = strlen(argv[1]);
> >     char myArray[len];
> >     printf("myArray: len=%i\n", len);
> 
> Displaying sizeof(myArray) is more useful confirmation. Otherwise this 
> line will give a result even if the char myArray line didn't exist.
> 
> >     myArray[0] = 'A';
> >     myArray[1] = '\0';
> 
> This assumes that len is at least two. And below, that it is a least 4. 
> But len can be 0 or 1.
> 
> >     int len2 = strlen(myArray);
> >     printf("myArray: len2=%i\n", len2);
> >     myArray[0] = 'A';
> >     myArray[1] = 'B';
> >     myArray[2] = 'C';
> >     myArray[3] = '\0';
> 
> -- 
> Bartc

Hi Bart:

Yes, I know that is not really ok, but just was a quick test to see if works.
At the command line I've make sure that the input have at least 4-5 chars in the parameter.

Thanks.-

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


#101850

From"James R. Kuyper" <jameskuyper@verizon.net>
Date2017-01-15 12:25 -0500
Message-ID<f06cce0d-a56b-2b30-506e-4db234bee984@verizon.net>
In reply to#101847
On 01/15/2017 11:45 AM, Fernando D. Bozzo wrote:
> From the beginning of my course I'm looking a way to define an array with a number of elements based on some other variable which I don't know, but without using the dynamic memory space (with malloc)
>
> May be I have a conceptual error here, but just in case I did prefer to ask.
>
> I want to do something like this:
>
> len = (some calculated length that can vary in every execution);
> char myArray[len];
>
>
> I've tryied this way, but didn't compile. My aim is not needing to free() it later, but that this array get cleared as all other auto variables.

In C90, all arrays were required to have a length that was an integer 
constant expression. In C99, this was changed for arrays with no linkage 
and either block scope or function prototype scope, unless they had 
static or thread storage duration (6.7.6.2p2). An array whose length is 
not a constant, or whose element type does not have a known constant 
size, is referred to as a Variable Length Array (VLA) (6.7.6.2p4). In 
C2011, support for VLAs was made optional - if they are not supported, 
the implementation must pre#define __STDC_NO_VLA__ to a value of 1.

I've just given you a lot of jargon: integer constant expression, 
linkage, block scope, function prototype scope, static storage duration, 
thread storage duration, known constant size. I did that because I 
normally try to be as precise as possible - each of those terms has a 
precisely defined meaning in the C standard, which might be 
significantly different from what you'd expect from ordinary English 
usage. For example, not all constant expressions with integer type 
qualify as integer constant expressions.
I don't expect you, as a newbie, to know all of those terms, but I'm not 
sure which ones need explaining. If you have any question about any of 
those terms, let me know, and I can explain them in more detail.

What this all means is that if the code you give above won't compile, 
you're probably either using a C90 compiler, or a C2011 compiler that 
has __STDC_NO_VLA__ pre#defined to a value of 1.

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


#101861

From"Fernando D. Bozzo" <fdbozzo@gmail.com>
Date2017-01-15 10:46 -0800
Message-ID<a3ba2154-b48c-43c3-9d22-6fce40f76af1@googlegroups.com>
In reply to#101850
El domingo, 15 de enero de 2017, 18:26:04 (UTC+1), James R. Kuyper  escribió:
> On 01/15/2017 11:45 AM, Fernando D. Bozzo wrote:
> > From the beginning of my course I'm looking a way to define an array with a number of elements based on some other variable which I don't know, but without using the dynamic memory space (with malloc)
> >
> > May be I have a conceptual error here, but just in case I did prefer to ask.
> >
> > I want to do something like this:
> >
> > len = (some calculated length that can vary in every execution);
> > char myArray[len];
> >
> >
> > I've tryied this way, but didn't compile. My aim is not needing to free() it later, but that this array get cleared as all other auto variables.
> 
> In C90, all arrays were required to have a length that was an integer 
> constant expression. In C99, this was changed for arrays with no linkage 
> and either block scope or function prototype scope, unless they had 
> static or thread storage duration (6.7.6.2p2). An array whose length is 
> not a constant, or whose element type does not have a known constant 
> size, is referred to as a Variable Length Array (VLA) (6.7.6.2p4). In 
> C2011, support for VLAs was made optional - if they are not supported, 
> the implementation must pre#define __STDC_NO_VLA__ to a value of 1.
> 
> I've just given you a lot of jargon: integer constant expression, 
> linkage, block scope, function prototype scope, static storage duration, 
> thread storage duration, known constant size. I did that because I 
> normally try to be as precise as possible - each of those terms has a 
> precisely defined meaning in the C standard, which might be 
> significantly different from what you'd expect from ordinary English 
> usage. For example, not all constant expressions with integer type 
> qualify as integer constant expressions.
> I don't expect you, as a newbie, to know all of those terms, but I'm not 
> sure which ones need explaining. If you have any question about any of 
> those terms, let me know, and I can explain them in more detail.
> 
> What this all means is that if the code you give above won't compile, 
> you're probably either using a C90 compiler, or a C2011 compiler that 
> has __STDC_NO_VLA__ pre#defined to a value of 1.


Thanks for the highly detailed technical info James. I don't understand all of it now, but surely I will do it more over time.

Last part is very clear. I'm using Ubuntu Linux 64 bits and the clang compiler, and in my recent test it did work ok.

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


#101875

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2017-01-15 20:13 +0000
Message-ID<874m10jd3h.fsf@bsb.me.uk>
In reply to#101861
"Fernando D. Bozzo" <fdbozzo@gmail.com> writes:

>> On 01/15/2017 11:45 AM, Fernando D. Bozzo wrote:
<snip>
>> > I want to do something like this:
>> >
>> > len = (some calculated length that can vary in every execution);
>> > char myArray[len];
<snip>
> ... I'm using Ubuntu Linux 64 bits and the clang
> compiler, and in my recent test it did work ok.

VLAs almost certainly work then.  You need to ask for -std=c99 (or
-std=c11) but if that fails you would have to post the error message.
Something else might be wrong.

-- 
Ben.

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


#101889

From"Fernando D. Bozzo" <fdbozzo@gmail.com>
Date2017-01-15 15:06 -0800
Message-ID<81a3226f-a3c9-4d74-b67a-1145888844fa@googlegroups.com>
In reply to#101875
El domingo, 15 de enero de 2017, 21:13:48 (UTC+1), Ben Bacarisse  escribió:
> "Fernando D. Bozzo" writes:
> 
> >> On 01/15/2017 11:45 AM, Fernando D. Bozzo wrote:
> <snip>
> >> > I want to do something like this:
> >> >
> >> > len = (some calculated length that can vary in every execution);
> >> > char myArray[len];
> <snip>
> > ... I'm using Ubuntu Linux 64 bits and the clang
> > compiler, and in my recent test it did work ok.
> 
> VLAs almost certainly work then.  You need to ask for -std=c99 (or
> -std=c11) but if that fails you would have to post the error message.
> Something else might be wrong.
> 
> -- 
> Ben.

Hi Ben:

It's working beautifuly :)

I'm using -std=c11

Thanks!

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


#101880

FromKeith Thompson <kst-u@mib.org>
Date2017-01-15 12:46 -0800
Message-ID<lnmvesgigl.fsf@kst-u.example.com>
In reply to#101850
"James R. Kuyper" <jameskuyper@verizon.net> writes:
[...]
> What this all means is that if the code you give above won't compile, 
> you're probably either using a C90 compiler, or a C2011 compiler that 
> has __STDC_NO_VLA__ pre#defined to a value of 1.

Are there any such compilers?

-- 
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] | [next] | [standalone]


#101884

From"James R. Kuyper" <jameskuyper@verizon.net>
Date2017-01-15 16:10 -0500
Message-ID<5033b0f5-e2d2-8e93-d2f8-c4ac8ef0dfc9@verizon.net>
In reply to#101880
On 01/15/2017 03:46 PM, Keith Thompson wrote:
> "James R. Kuyper" <jameskuyper@verizon.net> writes:
> [...]
>> What this all means is that if the code you give above won't compile,
>> you're probably either using a C90 compiler, or a C2011 compiler that
>> has __STDC_NO_VLA__ pre#defined to a value of 1.
>
> Are there any such compilers?

I presume that you're referring only to the last clause of that sentence 
- C90 compilers are ubiquitous.

You should know me by now - I know a lot about what the standard allows 
and requires, but I'm not well-informed about which particular compilers 
take advantage of those allowances, or fail to meet those requirements. 
The only C compiler I know well from recent personal experience is gcc. 
It's been six years since I last had access to a machine with the IRIX C 
compiler installed, about 20 years since I had access to the Microsoft C 
compiler, and 27 years since I had access to the VMS C compiler - those 
are the four C compilers I've used most recently.

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


#101913

FromTim Rentsch <txr@alumni.caltech.edu>
Date2017-01-15 20:37 -0800
Message-ID<kfn1sw3lix1.fsf@x-alumni2.alumni.caltech.edu>
In reply to#101880
Keith Thompson <kst-u@mib.org> writes:

> "James R.  Kuyper" <jameskuyper@verizon.net> writes:
> [...]
>> What this all means is that if the code you give above won't compile,
>> you're probably either using a C90 compiler, or a C2011 compiler that
>> has __STDC_NO_VLA__ pre#defined to a value of 1.
>
> Are there any such compilers?

A C11 implementation that supports VLA's could provide a compiler
option that would disable them and define __STDC_NO_VLA__ to 1.
Such an option might even be useful, to check a non-VLA version
of C11 code, or to comply with an external requirement that VLA's
not be used.

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


#101917

FromKeith Thompson <kst-u@mib.org>
Date2017-01-15 21:02 -0800
Message-ID<lnk29vfvhc.fsf@kst-u.example.com>
In reply to#101913
Tim Rentsch <txr@alumni.caltech.edu> writes:
> Keith Thompson <kst-u@mib.org> writes:
>> "James R.  Kuyper" <jameskuyper@verizon.net> writes:
>> [...]
>>> What this all means is that if the code you give above won't compile,
>>> you're probably either using a C90 compiler, or a C2011 compiler that
>>> has __STDC_NO_VLA__ pre#defined to a value of 1.
>>
>> Are there any such compilers?
>
> A C11 implementation that supports VLA's could provide a compiler
> option that would disable them and define __STDC_NO_VLA__ to 1.
> Such an option might even be useful, to check a non-VLA version
> of C11 code, or to comply with an external requirement that VLA's
> not be used.

Yes, but that doesn't answer my question.

-- 
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] | [next] | [standalone]


#102744

FromTim Rentsch <txr@alumni.caltech.edu>
Date2017-01-30 04:23 -0800
Message-ID<kfnr33khh2v.fsf@x-alumni2.alumni.caltech.edu>
In reply to#101917
Keith Thompson <kst-u@mib.org> writes:

> Tim Rentsch <txr@alumni.caltech.edu> writes:
>> Keith Thompson <kst-u@mib.org> writes:
>>> "James R.  Kuyper" <jameskuyper@verizon.net> writes:
>>> [...]
>>>> What this all means is that if the code you give above won't compile,
>>>> you're probably either using a C90 compiler, or a C2011 compiler that
>>>> has __STDC_NO_VLA__ pre#defined to a value of 1.
>>>
>>> Are there any such compilers?
>>
>> A C11 implementation that supports VLA's could provide a compiler
>> option that would disable them and define __STDC_NO_VLA__ to 1.
>> Such an option might even be useful, to check a non-VLA version
>> of C11 code, or to comply with an external requirement that VLA's
>> not be used.
>
> Yes, but that doesn't answer my question.

You're right, it doesn't.  The point of my comment is that
it might be difficult to determine an answer.  I'm sorry
that wasn't more clear in the earlier posting.

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


#101929

FromDavid Brown <david.brown@hesbynett.no>
Date2017-01-16 09:05 +0100
Message-ID<o5hupi$mp6$1@dont-email.me>
In reply to#101913
On 16/01/17 05:37, Tim Rentsch wrote:
> Keith Thompson <kst-u@mib.org> writes:
> 
>> "James R.  Kuyper" <jameskuyper@verizon.net> writes:
>> [...]
>>> What this all means is that if the code you give above won't compile,
>>> you're probably either using a C90 compiler, or a C2011 compiler that
>>> has __STDC_NO_VLA__ pre#defined to a value of 1.
>>
>> Are there any such compilers?
> 
> A C11 implementation that supports VLA's could provide a compiler
> option that would disable them and define __STDC_NO_VLA__ to 1.

As a sample point, gcc can effectively disable VLA's with "-Werror=vla".
 But it does not define __STDC_NO_VLA__.

> Such an option might even be useful, to check a non-VLA version
> of C11 code, or to comply with an external requirement that VLA's
> not be used.
> 

I am at a loss to imagine a case where it would be useful to have a
non-VLA version of C11 code, unless there really exist compilers that
support C11 except VLA's.  Otherwise, apparently the only use of the
"feature" of __STDC_NO_VLA__ is to test code when that "feature" is present!

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


#101930

FromIan Collins <ian-news@hotmail.com>
Date2017-01-16 21:16 +1300
Message-ID<ee3dqcFc8p6U1@mid.individual.net>
In reply to#101929
On 01/16/17 09:05 PM, David Brown wrote:
>
> I am at a loss to imagine a case where it would be useful to have a
> non-VLA version of C11 code, unless there really exist compilers that
> support C11 except VLA's.  Otherwise, apparently the only use of the
> "feature" of __STDC_NO_VLA__ is to test code when that "feature" is present!

I would cite embedded code where one has to be able to determine stack 
use through static analysis.  Or were you thinking of two versions of 
the same code, one with and one without VLAs?

-- 
Ian

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


#101934

FromDavid Brown <david.brown@hesbynett.no>
Date2017-01-16 09:48 +0100
Message-ID<o5i1ab$ts6$1@dont-email.me>
In reply to#101930
On 16/01/17 09:16, Ian Collins wrote:
> On 01/16/17 09:05 PM, David Brown wrote:
>>
>> I am at a loss to imagine a case where it would be useful to have a
>> non-VLA version of C11 code, unless there really exist compilers that
>> support C11 except VLA's.  Otherwise, apparently the only use of the
>> "feature" of __STDC_NO_VLA__ is to test code when that "feature" is
>> present!
> 
> I would cite embedded code where one has to be able to determine stack
> use through static analysis.  Or were you thinking of two versions of
> the same code, one with and one without VLAs?
> 

Certainly one might want to avoid VLA's in embedded code - or anywhere
else where you are trying to limit or analyse stack usage.  Compiler
flags to warn on VLA's, or large stack frames, can be useful there.

But Tim was, I believe, talking about code such as:

#ifndef __STDC_NO_VLA__
	// Code using VLA's
#else
	// Code using malloc, alloca, or something else
#endif


I am wondering where you would use such code.

I can understand using somewhat more refined tests, perhaps based on
what you know of the limits to the sizes of the array:

#ifdef USE_VLA_FOR_THIS_BIT_OF_CODE
	// Code using VLA's
#else
	// Code using malloc, alloca, or something else
#endif


And certainly run-time choices might make sense:

if (size < limit) {
	// Code using VLA's
} else {
	// Code using malloc, alloca, or something else
}


However, if no real-world compilers actually fail to support VLAs, and
therefore none define __STDC_NO_VLA__ normally, then code with
conditional compilation based on that symbol is not going to be useful.

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


#101851

Fromfir <profesor.fir@gmail.com>
Date2017-01-15 09:29 -0800
Message-ID<f0d7fe7f-e1f2-4897-879c-a5b754bba7a0@googlegroups.com>
In reply to#101847
W dniu niedziela, 15 stycznia 2017 17:45:57 UTC+1 użytkownik Fernando D. Bozzo napisał:
> From the beginning of my course I'm looking a way to define an array with a number of elements based on some other variable which I don't know, but without using the dynamic memory space (with malloc)
> 
> May be I have a conceptual error here, but just in case I did prefer to ask.
> 
> I want to do something like this:
> 
> len = (some calculated length that can vary in every execution);
> char myArray[len];
> 
> 
> I've tryied this way, but didn't compile. My aim is not needing to free() it later, but that this array get cleared as all other auto variables.
> 
> 
it is also possible that when you declare big static 
array like

char table[200*1024*1024];

some systems (like windows) will only attach physical memory 'on touch' i mean if you will be using only 
first 10% of it rest will not really be physically 
allocked/consumed
(sadly i dont know the details (best would be to get practical method of checking which pages are allocked 
and which adress space is hanging unattached)

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


#101853

Fromfir <profesor.fir@gmail.com>
Date2017-01-15 09:37 -0800
Message-ID<cedd4af5-20e8-4ec4-adb7-60eaaf735977@googlegroups.com>
In reply to#101851
W dniu niedziela, 15 stycznia 2017 18:29:39 UTC+1 użytkownik fir napisał:
> W dniu niedziela, 15 stycznia 2017 17:45:57 UTC+1 użytkownik Fernando D. Bozzo napisał:
> > From the beginning of my course I'm looking a way to define an array with a number of elements based on some other variable which I don't know, but without using the dynamic memory space (with malloc)
> > 
> > May be I have a conceptual error here, but just in case I did prefer to ask.
> > 
> > I want to do something like this:
> > 
> > len = (some calculated length that can vary in every execution);
> > char myArray[len];
> > 
> > 
> > I've tryied this way, but didn't compile. My aim is not needing to free() it later, but that this array get cleared as all other auto variables.
> > 
> > 
> it is also possible that when you declare big static 
> array like
> 
> char table[200*1024*1024];
> 
> some systems (like windows) will only attach physical memory 'on touch' i mean if you will be using only 
> first 10% of it rest will not really be physically 
> allocked/consumed
> (sadly i dont know the details (best would be to get practical method of checking which pages are allocked 
> and which adress space is hanging unattached)

more see probably in msdn (i was reading there like 5 years ago and i dont exactly remember the details - if i will got a time to read there i could do some summary here later)

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


#101857

Fromfir <profesor.fir@gmail.com>
Date2017-01-15 09:56 -0800
Message-ID<85a9df6f-eb0b-4477-898b-c3c9b9e08194@googlegroups.com>
In reply to#101851
W dniu niedziela, 15 stycznia 2017 18:29:39 UTC+1 użytkownik fir napisał:
> W dniu niedziela, 15 stycznia 2017 17:45:57 UTC+1 użytkownik Fernando D. Bozzo napisał:
> > From the beginning of my course I'm looking a way to define an array with a number of elements based on some other variable which I don't know, but without using the dynamic memory space (with malloc)
> > 
> > May be I have a conceptual error here, but just in case I did prefer to ask.
> > 
> > I want to do something like this:
> > 
> > len = (some calculated length that can vary in every execution);
> > char myArray[len];
> > 
> > 
> > I've tryied this way, but didn't compile. My aim is not needing to free() it later, but that this array get cleared as all other auto variables.
> > 
> > 
> it is also possible that when you declare big static 
> array like
> 
> char table[200*1024*1024];
> 
> some systems (like windows) will only attach physical memory 'on touch' i mean if you will be using only 
> first 10% of it rest will not really be physically 
> allocked/consumed
> (sadly i dont know the details (best would be to get practical method of checking which pages are allocked 
> and which adress space is hanging unattached)

note btw by the advantages and disadvantages of this (quite interesting) solution:

- youre sure thet no memory will be moved (ADV)

- youre consuming logical range (DISADV)

- you got no clasic c api to control this (DISADV)

- if you would want controll this not much will 
be needed sorta like two functions 

attach(char* begin, char* end); 
detach(char* begin, char* end);

and if you will have that, the underlying operations
are more lightweight and strict than those below
malloc/ralloc/free                  (ADV)

[in general for sure i would like to go into that;
yet specially it may allow thinking even more on
underlying paging system and do some cheap tricks ;c)

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


#101858

Fromfir <profesor.fir@gmail.com>
Date2017-01-15 10:34 -0800
Message-ID<0a4360c9-7b79-4bff-9523-4f98e493259a@googlegroups.com>
In reply to#101857
yet probably there could be mentioned that if system 
wendors (mean like intel/microsoft) would redefine 
paging system it probably could be possible to resize
all arraus freely 
(im talking probably coz im not sure if todays paging
hardware is able to do that with not bigger changes
but probably only some small would be needed - im not sure 
though)

i mean when today pages are all build in linear common 
space tehere would be a need that each array would open
its own 'orthogonal' space and in such adressing like tab[i] i would be adressing (from 0 to end) this orthogonal space named tab

you could have one horisontal ram space and a number of
vertical ones for arrays.. im not sure though if it would bring big convenience or efficiency improvements (maybe some, i dont know, but at least it seem an option to me)

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


#101862

From"Fernando D. Bozzo" <fdbozzo@gmail.com>
Date2017-01-15 10:48 -0800
Message-ID<3cd95563-79be-4b47-b5a5-ae2baf7f9ebe@googlegroups.com>
In reply to#101851
El domingo, 15 de enero de 2017, 18:29:39 (UTC+1), fir  escribió:
<snip> 
> > 
> it is also possible that when you declare big static 
> array like
> 
> char table[200*1024*1024];
> 
> some systems (like windows) will only attach physical memory 'on touch' i mean if you will be using only 
> first 10% of it rest will not really be physically 
> allocked/consumed
> (sadly i dont know the details (best would be to get practical method of checking which pages are allocked 
> and which adress space is hanging unattached)


I'm trying to stay between the size of the stack (I think it's 8 MB? on Ubuntu), so I never use large arrays with this VLAs.

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


#101863

Fromfir <profesor.fir@gmail.com>
Date2017-01-15 11:10 -0800
Message-ID<6a1a466f-85d8-45e5-b68d-48534273903b@googlegroups.com>
In reply to#101862
W dniu niedziela, 15 stycznia 2017 19:49:05 UTC+1 użytkownik Fernando D. Bozzo napisał:
> El domingo, 15 de enero de 2017, 18:29:39 (UTC+1), fir  escribió:
> <snip> 
> > > 
> > it is also possible that when you declare big static 
> > array like
> > 
> > char table[200*1024*1024];
> > 
> > some systems (like windows) will only attach physical memory 'on touch' i mean if you will be using only 
> > first 10% of it rest will not really be physically 
> > allocked/consumed
> > (sadly i dont know the details (best would be to get practical method of checking which pages are allocked 
> > and which adress space is hanging unattached)
> 
> 
> I'm trying to stay between the size of the stack (I think it's 8 MB? on Ubuntu), so I never use large arrays with this VLAs.

on windows stack size is contained as a field in binary (in exe file),  you may set this size in compiler comandline option 

i always forget the details on this as this may vary betwean compiler and maybe also system/os versions

you could probably set bigger than 8 MB (even probably 100 
(500?) MB would go and probably os will respect that

[i made only tests on winxp longer time ago it was afair 
1 or 2 MB by default but i could set it bigger]

(afaik though stack is in this way special that it has 
some trep based resizing system - same or close as in those 
big static array case i mentioned above , i mean eben if you set stack to 8 MB only some pages are attached (like say 128 kB) it will only attached on touch (and probably deatachhed if stack pointer gets back - thus im not sure if
frequent resizes will not suffer form this attaching/deattaching penalty [but im not sure as to 
this, so treat this info as ;unchecked ;C ]
array

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


Page 2 of 8 — ← Prev page 1 [2] 3 4 5 6 7 8  Next page →

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


csiph-web