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


Groups > comp.lang.c++ > #19026 > unrolled thread

C/C++ question about dynamic "static struct"

Started bygus gassmann <gus@nospam.com>
First post2012-10-17 06:49 -0300
Last post2012-10-19 07:37 -0400
Articles 13 on this page of 153 — 30 participants

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


Contents

  C/C++ question about dynamic "static struct" gus gassmann <gus@nospam.com> - 2012-10-17 06:49 -0300
    Re: C/C++ question about dynamic "static struct" Noob <root@127.0.0.1> - 2012-10-17 13:08 +0200
      Re: C/C++ question about dynamic "static struct" James Kuyper <jameskuyper@verizon.net> - 2012-10-17 08:19 -0400
      Re: C/C++ question about dynamic "static struct" Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-10-17 15:19 +0000
      Re: C/C++ question about dynamic "static struct" gus gassmann <gus@nospam.com> - 2012-10-17 18:47 -0300
        Re: C/C++ question about dynamic "static struct" Ike Naar <ike@iceland.freeshell.org> - 2012-10-17 22:46 +0000
          Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-18 07:13 +0000
        Re: C/C++ question about dynamic "static struct" James Kuyper <jameskuyper@verizon.net> - 2012-10-17 18:58 -0400
          Re: C/C++ question about dynamic "static struct" Stuart <DerTopper@web.de> - 2012-10-18 09:55 +0200
            Re: C/C++ question about dynamic "static struct" jacob navia <jacob@spamsink.net> - 2012-10-18 10:13 +0200
              Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-18 08:23 +0000
                Re: C/C++ question about dynamic "static struct" jacob navia <jacob@spamsink.net> - 2012-10-18 11:17 +0200
                  Re: C/C++ question about dynamic "static struct" Ian Collins <ian-news@hotmail.com> - 2012-10-18 23:37 +1300
                  Re: C/C++ question about dynamic "static struct" Rui Maciel <rui.maciel@gmail.com> - 2012-10-18 15:35 +0100
                    Re: C/C++ question about dynamic "static struct" Öö Tiib <ootiib@hot.ee> - 2012-10-19 11:40 -0700
              Re: C/C++ question about dynamic "static struct" Ian Collins <ian-news@hotmail.com> - 2012-10-18 21:45 +1300
              Re: C/C++ question about dynamic "static struct" Rui Maciel <rui.maciel@gmail.com> - 2012-10-18 15:03 +0100
            Re: C/C++ question about dynamic "static struct" James Kuyper <jameskuyper@verizon.net> - 2012-10-18 07:18 -0400
              Re: C/C++ question about dynamic "static struct" Stuart <DerTopper@web.de> - 2012-10-18 17:43 +0200
            Re: C/C++ question about dynamic "static struct" William Ahern <william@wilbur.25thandClement.com> - 2012-10-18 13:52 -0700
              Re: C/C++ question about dynamic "static struct" Ian Collins <ian-news@hotmail.com> - 2012-10-19 21:34 +1300
              Re: C/C++ question about dynamic "static struct" Stuart <DerTopper@web.de> - 2012-10-19 11:03 +0200
                Re: C/C++ question about dynamic "static struct" "BartC" <bc@freeuk.com> - 2012-10-20 14:03 +0100
              Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-19 09:27 +0000
                Re: C/C++ question about dynamic "static struct" Stuart <DerTopper@web.de> - 2012-10-19 13:43 +0200
                  Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-19 12:46 +0000
                    Re: C/C++ question about dynamic "static struct" ImpalerCore <jadill33@gmail.com> - 2012-10-19 10:14 -0700
                    Re: C/C++ question about dynamic "static struct" Paavo Helde <myfirstname@osa.pri.ee> - 2012-10-19 14:53 -0500
                      Re: C/C++ question about dynamic "static struct" Öö Tiib <ootiib@hot.ee> - 2012-10-19 13:52 -0700
                        Re: C/C++ question about dynamic "static struct" Öö Tiib <ootiib@hot.ee> - 2012-10-19 14:13 -0700
                        Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-19 21:24 +0000
                          Re: C/C++ question about dynamic "static struct" Ian Collins <ian-news@hotmail.com> - 2012-10-20 11:47 +1300
                      Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-19 21:22 +0000
                Re: C/C++ question about dynamic "static struct" William Ahern <william@wilbur.25thandClement.com> - 2012-10-19 11:21 -0700
                  Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-19 21:29 +0000
                    Re: C/C++ question about dynamic "static struct" James Kuyper <jameskuyper@verizon.net> - 2012-10-19 18:53 -0400
                      Re: C/C++ question about dynamic "static struct" Ian Collins <ian-news@hotmail.com> - 2012-10-20 12:13 +1300
                        Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-20 05:55 +0000
                          Re: C/C++ question about dynamic "static struct" Stuart <DerTopper@web.de> - 2012-10-20 13:24 +0200
                            Re: C/C++ question about dynamic "static struct" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-20 12:54 +0100
                            Re: C/C++ question about dynamic "static struct" Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-10-20 06:45 -0700
                              Re: C/C++ question about dynamic "static struct" Ian Collins <ian-news@hotmail.com> - 2012-10-21 09:20 +1300
                              Re: C/C++ question about dynamic "static struct" Dombo <dombo@disposable.invalid> - 2012-10-20 22:28 +0200
                              Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-21 07:05 +0000
                                Re: C/C++ question about dynamic "static struct" Les Cargill <lcargill99@comcast.com> - 2012-10-21 02:23 -0500
                                  Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-21 07:32 +0000
                                    Re: C/C++ question about dynamic "static struct" "BartC" <bc@freeuk.com> - 2012-10-21 11:56 +0100
                                    Re: C/C++ question about dynamic "static struct" Les Cargill <lcargill99@comcast.com> - 2012-10-21 12:54 -0500
                                      Re: C/C++ question about dynamic "static struct" ptyxs <kerloch@gmail.com> - 2012-10-22 13:43 +0200
                                        Re: C/C++ question about dynamic "static struct" gwowen <gwowen@gmail.com> - 2012-10-26 03:37 -0700
                                          Re: C/C++ question about dynamic "static struct" Les Cargill <lcargill99@comcast.com> - 2012-10-26 07:33 -0500
                                    Re: C/C++ question about dynamic "static struct" Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-10-27 05:14 -0700
                                Re: C/C++ question about dynamic "static struct" Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-10-27 05:08 -0700
                          Re: C/C++ question about dynamic "static struct" Les Cargill <lcargill99@comcast.com> - 2012-10-20 13:44 -0500
                            Re: C/C++ question about dynamic "static struct" Ian Collins <ian-news@hotmail.com> - 2012-10-21 09:09 +1300
                              Re: C/C++ question about dynamic "static struct" Dombo <dombo@disposable.invalid> - 2012-10-20 22:31 +0200
                              Re: C/C++ question about dynamic "static struct" Les Cargill <lcargill99@comcast.com> - 2012-10-21 02:11 -0500
                                Re: C/C++ question about dynamic "static struct" Ian Collins <ian-news@hotmail.com> - 2012-10-21 20:28 +1300
                                  Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-21 07:40 +0000
                                  Re: C/C++ question about dynamic "static struct" Les Cargill <lcargill99@comcast.com> - 2012-10-21 13:31 -0500
                                    Re: C/C++ question about dynamic "static struct" Ian Collins <ian-news@hotmail.com> - 2012-10-22 08:41 +1300
                                      Re: C/C++ question about dynamic "static struct" Les Cargill <lcargill99@comcast.com> - 2012-10-21 16:24 -0500
                                        Re: C/C++ question about dynamic "static struct" Öö Tiib <ootiib@hot.ee> - 2012-10-21 15:05 -0700
                                        Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-22 07:52 +0000
                                          Re: C/C++ question about dynamic "static struct" Les Cargill <lcargill99@comcast.com> - 2012-10-22 14:02 -0500
                                            Re: C/C++ question about dynamic "static struct" gwowen <gwowen@gmail.com> - 2012-10-26 03:41 -0700
                                              Re: C/C++ question about dynamic "static struct" Les Cargill <lcargill99@comcast.com> - 2012-10-26 07:53 -0500
                                                Re: C/C++ question about dynamic "static struct" James Kuyper <jameskuyper@verizon.net> - 2012-10-26 09:51 -0400
                                                  Re: C/C++ question about dynamic "static struct" James Kuyper <jameskuyper@verizon.net> - 2012-10-26 13:48 -0400
                                                Re: C/C++ question about dynamic "static struct" ImpalerCore <jadill33@gmail.com> - 2012-10-26 07:35 -0700
                                                  Re: C/C++ question about dynamic "static struct" Paavo Helde <myfirstname@osa.pri.ee> - 2012-10-26 18:42 -0500
                                                    Re: C/C++ question about dynamic "static struct" ImpalerCore <jadill33@gmail.com> - 2012-10-27 04:21 -0700
                                                      Re: C/C++ question about dynamic "static struct" Öö Tiib <ootiib@hot.ee> - 2012-10-27 05:04 -0700
                                                      Re: C/C++ question about dynamic "static struct" Paavo Helde <myfirstname@osa.pri.ee> - 2012-10-27 08:06 -0500
                                                        Re: C/C++ question about dynamic "static struct" ImpalerCore <jadill33@gmail.com> - 2012-10-27 06:50 -0700
                                                          Re: C/C++ question about dynamic "static struct" Paavo Helde <myfirstname@osa.pri.ee> - 2012-10-27 11:13 -0500
                                                            Re: C/C++ question about dynamic "static struct" ImpalerCore <jadill33@gmail.com> - 2012-10-27 12:02 -0700
                                                              Re: C/C++ question about dynamic "static struct" Paavo Helde <myfirstname@osa.pri.ee> - 2012-10-27 15:46 -0500
                                                                Re: C/C++ question about dynamic "static struct" ImpalerCore <jadill33@gmail.com> - 2012-10-27 20:24 -0700
                                                      Re: C/C++ question about dynamic "static struct" Dombo <dombo@disposable.invalid> - 2012-10-27 20:11 +0200
                                                Re: C/C++ question about dynamic "static struct" Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-10-27 05:43 -0700
                                                  Re: C/C++ question about dynamic "static struct" Les Cargill <lcargill99@comcast.com> - 2012-10-27 13:52 -0500
                                                  Re: C/C++ question about dynamic "static struct" Les Cargill <lcargill99@comcast.com> - 2012-10-27 14:40 -0500
                                        Re: C/C++ question about dynamic "static struct" google@ianshome.com - 2012-10-23 12:03 -0700
                                Re: C/C++ question about dynamic "static struct" Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-10-27 05:35 -0700
                                  Re: C/C++ question about dynamic "static struct" Les Cargill <lcargill99@comcast.com> - 2012-10-27 14:24 -0500
                                Re: C/C++ question about dynamic "static struct" Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-10-27 05:36 -0700
                            Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-21 07:08 +0000
                              Re: C/C++ question about dynamic "static struct" Les Cargill <lcargill99@comcast.com> - 2012-10-21 02:51 -0500
                                Re: C/C++ question about dynamic "static struct" Ian Collins <ian-news@hotmail.com> - 2012-10-21 21:09 +1300
                                Re: C/C++ question about dynamic "static struct" Rui Maciel <rui.maciel@gmail.com> - 2012-10-21 12:16 +0100
                            Re: C/C++ question about dynamic "static struct" Rui Maciel <rui.maciel@gmail.com> - 2012-10-21 11:55 +0100
                              Re: C/C++ question about dynamic "static struct" Les Cargill <lcargill99@comcast.com> - 2012-10-21 13:47 -0500
                                Re: C/C++ question about dynamic "static struct" Ian Collins <ian-news@hotmail.com> - 2012-10-22 08:46 +1300
                                Re: C/C++ question about dynamic "static struct" Rui Maciel <rui.maciel@gmail.com> - 2012-10-22 03:02 +0100
                                Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-22 08:04 +0000
                              Re: C/C++ question about dynamic "static struct" Tobias Müller <troplin@bluewin.ch> - 2012-10-21 18:54 +0000
                                Re: C/C++ question about dynamic "static struct" Ian Collins <ian-news@hotmail.com> - 2012-10-22 08:49 +1300
                                  Re: C/C++ question about dynamic "static struct" Tobias Müller <troplin@bluewin.ch> - 2012-10-21 20:07 +0000
                                    Re: C/C++ question about dynamic "static struct" Öö Tiib <ootiib@hot.ee> - 2012-10-21 13:53 -0700
                                    Re: C/C++ question about dynamic "static struct" Ian Collins <ian-news@hotmail.com> - 2012-10-22 09:54 +1300
                                    Re: C/C++ question about dynamic "static struct" Rui Maciel <rui.maciel@gmail.com> - 2012-10-22 02:41 +0100
                                      Re: C/C++ question about dynamic "static struct" Tobias Müller <troplin@bluewin.ch> - 2012-10-22 06:12 +0000
                                      Re: C/C++ question about dynamic "static struct" Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-10-22 20:52 +0000
                                        Re: C/C++ question about dynamic "static struct" Öö Tiib <ootiib@hot.ee> - 2012-10-22 16:30 -0700
                                          Re: C/C++ question about dynamic "static struct" Stuart <DerTopper@web.de> - 2012-10-23 11:22 +0200
                                            Re: C/C++ question about dynamic "static struct" Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-10-23 16:58 +0000
                                Re: C/C++ question about dynamic "static struct" Rui Maciel <rui.maciel@gmail.com> - 2012-10-22 02:22 +0100
                            Re: C/C++ question about dynamic "static struct" Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-10-27 05:30 -0700
                        Re: C/C++ question about dynamic "static struct" James Kuyper <jameskuyper@verizon.net> - 2012-10-20 09:06 -0400
                          Re: C/C++ question about dynamic "static struct" Öö Tiib <ootiib@hot.ee> - 2012-10-20 07:43 -0700
                          Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-21 07:11 +0000
                            Re: C/C++ question about dynamic "static struct" Rui Maciel <rui.maciel@gmail.com> - 2012-10-21 11:56 +0100
                            Re: C/C++ question about dynamic "static struct" James Kuyper <jameskuyper@verizon.net> - 2012-10-21 07:43 -0400
                              Re: C/C++ question about dynamic "static struct" Öö Tiib <ootiib@hot.ee> - 2012-10-21 10:36 -0700
                              Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-22 08:13 +0000
                                Re: C/C++ question about dynamic "static struct" Steve Thompson <stevet810@gmail.com> - 2012-10-22 15:08 +0000
                                Re: C/C++ question about dynamic "static struct" James Kuyper <jameskuyper@verizon.net> - 2012-10-22 14:42 -0400
                          Re: C/C++ question about dynamic "static struct" Rui Maciel <rui.maciel@gmail.com> - 2012-10-21 10:12 +0100
                    Re: C/C++ question about dynamic "static struct" Les Cargill <lcargill99@comcast.com> - 2012-10-20 13:24 -0500
                      Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-21 07:16 +0000
                        Re: C/C++ question about dynamic "static struct" Les Cargill <lcargill99@comcast.com> - 2012-10-21 13:57 -0500
                          Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-22 08:17 +0000
                Re: C/C++ question about dynamic "static struct" Fritz Wuehler <fritz@spamexpire-201210.rodent.frell.theremailer.net> - 2012-10-20 22:41 +0200
                  Re: C/C++ question about dynamic "static struct" Dombo <dombo@disposable.invalid> - 2012-10-21 01:04 +0200
                  Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-21 07:23 +0000
              Re: C/C++ question about dynamic "static struct" Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-10-21 19:33 +0000
                Re: C/C++ question about dynamic "static struct" Greg Martin <greg@softsprocket.com> - 2012-10-21 13:20 -0700
                  Re: C/C++ question about dynamic "static struct" Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-10-23 15:44 +0000
                    Re: C/C++ question about dynamic "static struct" Dombo <dombo@disposable.invalid> - 2012-10-23 20:01 +0200
                      Re: C/C++ question about dynamic "static struct" Stuart <DerTopper@web.de> - 2012-10-24 12:01 +0200
                        Re: C/C++ question about dynamic "static struct" Dombo <dombo@disposable.invalid> - 2012-10-24 20:31 +0200
            Re: C/C++ question about dynamic "static struct" Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-10-20 06:13 -0700
              Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-21 07:25 +0000
                Re: C/C++ question about dynamic "static struct" Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-10-27 05:54 -0700
            Re: C/C++ question about dynamic "static struct" Old Wolf <oldwolf@inspire.net.nz> - 2012-11-11 14:58 -0800
              Re: C/C++ question about dynamic "static struct" gof@somewhere.invalid (Adam Wysocki) - 2012-11-12 10:33 +0000
        Re: C/C++ question about dynamic "static struct" Ian Collins <ian-news@hotmail.com> - 2012-10-18 12:19 +1300
      Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-18 07:06 +0000
        Re: C/C++ question about dynamic "static struct" Noob <root@127.0.0.1> - 2012-10-18 11:36 +0200
          Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-19 09:28 +0000
            Re: C/C++ question about dynamic "static struct" Noob <root@127.0.0.1> - 2012-10-19 12:07 +0200
              Re: C/C++ question about dynamic "static struct" gus gassmann <gus@nospam.com> - 2012-10-19 08:03 -0300
                Re: C/C++ question about dynamic "static struct" Fritz Wuehler <fritz@spamexpire-201210.rodent.frell.theremailer.net> - 2012-10-20 07:14 +0200
            Re: C/C++ question about dynamic "static struct" James Kuyper <jameskuyper@verizon.net> - 2012-10-19 06:58 -0400
    Re: C/C++ question about dynamic "static struct" James Kuyper <jameskuyper@verizon.net> - 2012-10-17 08:29 -0400
    Re: C/C++ question about dynamic "static struct" Richard Damon <news.x.richarddamon@xoxy.net> - 2012-10-17 08:35 -0400
      Re: C/C++ question about dynamic "static struct" James Kuyper <jameskuyper@verizon.net> - 2012-10-17 08:49 -0400
      Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-18 07:10 +0000
        Re: C/C++ question about dynamic "static struct" Keith Thompson <kst-u@mib.org> - 2012-10-18 12:11 -0700
          Re: C/C++ question about dynamic "static struct" Juha Nieminen <nospam@thanks.invalid> - 2012-10-19 09:30 +0000
            Re: C/C++ question about dynamic "static struct" Keith Thompson <kst-u@mib.org> - 2012-10-19 03:05 -0700
            Re: C/C++ question about dynamic "static struct" James Kuyper <jameskuyper@verizon.net> - 2012-10-19 07:37 -0400

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


#19070

FromJuha Nieminen <nospam@thanks.invalid>
Date2012-10-19 09:28 +0000
Message-ID<k5r6g5$at5$2@speranza.aioe.org>
In reply to#19046
In comp.lang.c++ Noob <root@127.0.0.1> wrote:
>> However, that's probably not what the OP meant because he explicitly
>> wanted to use an initializer list to initialize the array. Therefore
>> he probably didn't mean to imply that the size of the array is only
>> known at runtime.
> 
> Right, except for the fact that he wrote:
> 
> "I need to set dynamic values [...] where both the values and the number
> of values are only known at runtime."

Yes, so? I precisely said above that it's probably not what he meant
(because he wanted to use an initializer list.)

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


#19076

FromNoob <root@127.0.0.1>
Date2012-10-19 12:07 +0200
Message-ID<k5r8p6$g4d$1@dont-email.me>
In reply to#19070
Juha Nieminen wrote:

> In comp.lang.c++ Noob <root@127.0.0.1> wrote:
>>> However, that's probably not what the OP meant because he explicitly
>>> wanted to use an initializer list to initialize the array. Therefore
>>> he probably didn't mean to imply that the size of the array is only
>>> known at runtime.
>>
>> Right, except for the fact that he wrote:
>>
>> "I need to set dynamic values [...] where both the values and the number
>> of values are only known at runtime."
> 
> Yes, so? I precisely said above that it's probably not what he meant
> (because he wanted to use an initializer list.)

The initializer list is merely an illustration of the OP's /intent/
and he even realized that his illustration was not valid code:

"However, I need to set dynamic values along these lines
(I know that the code does not work)"

He then went on to state his /actual/ requirements:

"values and number of values are only known at runtime"

You can keep believing that "it's not just you", and "most of the
answers to the OP's question given in this thread [are] unusually
vague, incorrect and outright incompetent". I'm sure Dunning and
Kruger would love to include you in their follow-up study.

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


#19078

Fromgus gassmann <gus@nospam.com>
Date2012-10-19 08:03 -0300
Message-ID<k5rc1m$9jf$1@Kil-nws-1.UCIS.Dal.Ca>
In reply to#19076
On 19/10/2012 7:07 AM, Noob wrote:
> Juha Nieminen wrote:
>
>> In comp.lang.c++ Noob <root@127.0.0.1> wrote:
>>>> However, that's probably not what the OP meant because he explicitly
>>>> wanted to use an initializer list to initialize the array. Therefore
>>>> he probably didn't mean to imply that the size of the array is only
>>>> known at runtime.
>>>
>>> Right, except for the fact that he wrote:
>>>
>>> "I need to set dynamic values [...] where both the values and the number
>>> of values are only known at runtime."
>>
>> Yes, so? I precisely said above that it's probably not what he meant
>> (because he wanted to use an initializer list.)
>
> The initializer list is merely an illustration of the OP's /intent/
> and he even realized that his illustration was not valid code:
>
> "However, I need to set dynamic values along these lines
> (I know that the code does not work)"
>
> He then went on to state his /actual/ requirements:
>
> "values and number of values are only known at runtime"
>
> You can keep believing that "it's not just you", and "most of the
> answers to the OP's question given in this thread [are] unusually
> vague, incorrect and outright incompetent". I'm sure Dunning and
> Kruger would love to include you in their follow-up study.

At the risk of starting a flame war, but in the hopes of keeping down 
traffic: Noob's got it exactly right.

What threw me was the "static" keyword in the code sample that I was 
provided, combined with some bad experiences about ignoring things like 
that with this particular header file and a rather superficial 
understanding of the language. Thanks to Noob and others I got the code 
to work. So, even if the answers given were "vague, incorrect and 
outright incompetent", they got me on the right track. Now, if there 
were inefficiencies or other gotchas I need to watch out for going 
forward, I would love to hear about it.

Thanks.

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


#19114

FromFritz Wuehler <fritz@spamexpire-201210.rodent.frell.theremailer.net>
Date2012-10-20 07:14 +0200
Message-ID<5d010fde53231145b0ad39374a7099e6@msgid.frell.theremailer.net>
In reply to#19078
gus gassmann <gus@nospam.com> wrote:

> understanding of the language. Thanks to Noob and others I got the code 
> to work. So, even if the answers given were "vague, incorrect and 
> outright incompetent", they got me on the right track.

Didn't go through the thread but just because code seems to work doesn't
mean it's good code. There are plenty of bad ways to get code to produce
correct results.

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


#19077

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-10-19 06:58 -0400
Message-ID<k5rbol$i7$1@dont-email.me>
In reply to#19070
On 10/19/2012 05:28 AM, Juha Nieminen wrote:
> In comp.lang.c++ Noob <root@127.0.0.1> wrote:
>>> However, that's probably not what the OP meant because he explicitly
>>> wanted to use an initializer list to initialize the array. Therefore
>>> he probably didn't mean to imply that the size of the array is only
>>> known at runtime.
>>
>> Right, except for the fact that he wrote:
>>
>> "I need to set dynamic values [...] where both the values and the number
>> of values are only known at runtime."
> 
> Yes, so? I precisely said above that it's probably not what he meant
> (because he wanted to use an initializer list.)

Isn't it more likely that he was wrong about wanting to use an
initializer list (because he mistakenly thought that he could use it
this way), than that he was wrong about needing to set the values at run
time? That assumption seems to me to be much more consistent with what
he said.



-- 
James Kuyper

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


#19029

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-10-17 08:29 -0400
Message-ID<k5m8bb$fol$1@dont-email.me>
In reply to#19026
On 10/17/2012 05:49 AM, gus gassmann wrote:
> Hi,
> 
> I have a static struct, defined in a C header file as something like
> 
>   typedef struct
> SomeStruct {	
> 		char *name;
> 		int kind;
> 		int value;
> 	 }

That's not a valid typedef; it's not clear what you intended, but given
the code below, you should probably have moved 'SomeStruct' after the
right curly bracket, and then appended a semicolon.

> and I need to supply (in C++) values to an array of this type. I 
> understand that I can set *static* values by
> 
> static SomeStruct
> myStruct[] = {
> 		{"name1", 1, 17},
> 		{"name2", 7, 25},
> 		{"name3", 3,  6},
> 		{"name4", 0,117}
> 	      };
> 
> However, I need to set dynamic values along these lines (I know that the 
> code does not work):
> 
> static SomeStruct
> myStruct[] = {
> 		{name[0], kind[0], val[0]},
> 		{name[1], kind[1], val[1]},
> 		...	
> 		{name[n], kind[n], val[n]},
> 	      };
> 
> where both the values and the number of values are only known at 
> runtime. I cannot change the definition in the header file; I am not 
> even sure that what I want to do is possible. Any ideas?

It isn't possible to do this in the initializer of a static object. That
initializer is evaluated at the time the object is created, which for
objects with static storage duration, occurs at the start of the
program. If you want the values to be set at run time, you'll have to
use assignment expressions to fill it in, not initialization.

If the array's length is not known until run time, you can't make it a
static array; the best you can do is a static pointer to a dynamically
allocated array, which should be initialized with a null pointer. Make
sure that your code is written in such a way as to guarantee that the
pointer is not dereferenced while null. You could use malloc() to
allocate the array, in either language. However, since the array will be
filled in by C++ code, you'd be better off using a 'new' expression,
which has better type safety.
-- 
James Kuyper

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


#19030

FromRichard Damon <news.x.richarddamon@xoxy.net>
Date2012-10-17 08:35 -0400
Message-ID<k5m8ls$hvj$1@dont-email.me>
In reply to#19026
On 10/17/12 5:49 AM, gus gassmann wrote:
> 
> static SomeStruct
> myStruct[] = {
>         {name[0], kind[0], val[0]},
>         {name[1], kind[1], val[1]},
>         ...   
>         {name[n], kind[n], val[n]},
>           };
> 
> where both the values and the number of values are only known at
> runtime. I cannot change the definition in the header file; I am not
> even sure that what I want to do is possible. Any ideas?
> 
> Thanks
> 
> gus
> 
> 

Fundamental problem! A static (or any global) object MUST have a
compiler known size, you can NOT have its size determined at run time.

If its size is not know at compile time, then its memory allocation must
be dynamic. (In C99, but not C++ except as an extension, it could also
be of storage type auto).

This is a fundamental issue, any static/global object has a fixed
address range, so a fixed size. you need something without a fixed
address to store something of variable size (unless you can cap the size
and just always allocate the most space it will ever need).

In C and C++, this is done with the heap.

You could possible change your definition of myStruct to

static SomeStruct *myStruct;

And then create the array of SomeStructs and assign its address to
myStruct.

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


#19031

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-10-17 08:49 -0400
Message-ID<k5m9hm$mq2$1@dont-email.me>
In reply to#19030
On 10/17/2012 08:35 AM, Richard Damon wrote:
> On 10/17/12 5:49 AM, gus gassmann wrote:
...
> If its size is not know at compile time, then its memory allocation must
> be dynamic. (In C99, but not C++ except as an extension, it could also
> be of storage type auto).

Use of the 'auto' keyword is completely unnecessary in C, because it can
only be used in contexts where the object would have automatic storage
duration whether or not you used that keyword. In C++ the 'auto' keyword
cannot be used for this purpose, because it has been given a different,
much more useful meaning. However, automatic storage duration is the
default for objects declared with block scope in both C and C++.
-- 
James Kuyper

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


#19039

FromJuha Nieminen <nospam@thanks.invalid>
Date2012-10-18 07:10 +0000
Message-ID<k5oa1d$i1t$2@speranza.aioe.org>
In reply to#19030
In comp.lang.c++ Richard Damon <news.x.richarddamon@xoxy.net> wrote:
> If its size is not know at compile time, then its memory allocation must
> be dynamic. (In C99, but not C++ except as an extension, it could also
> be of storage type auto).

I think you are confusing variable-length arrays (in C) with the keyword
'auto', which has absolutely nothing to do with that (in either language).

(Btw, and I'm not talking about you specifically, but is it just me or
are most of the answers to the OP's question given in this thread
unusually vague, incorrect and outright incompetent?)

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


#19058

FromKeith Thompson <kst-u@mib.org>
Date2012-10-18 12:11 -0700
Message-ID<lnvce7ioin.fsf@nuthaus.mib.org>
In reply to#19039
Juha Nieminen <nospam@thanks.invalid> writes:
> In comp.lang.c++ Richard Damon <news.x.richarddamon@xoxy.net> wrote:
>> If its size is not know at compile time, then its memory allocation must
>> be dynamic. (In C99, but not C++ except as an extension, it could also
>> be of storage type auto).
>
> I think you are confusing variable-length arrays (in C) with the keyword
> 'auto', which has absolutely nothing to do with that (in either language).

Richard didn't mention the "auto" *keyword*.  I think his point is
that a VLA must have automatic storage duration ("storage type auto"
was not the best way to phrase that).

Which is true for *identifiers* defined as VLAs, but not for all VLAs:

    int x = /* whatever */;
    int y = /* whatever */;
    typedef double vla[x][y];
    vla *ptr = malloc(sizeof *ptr);
    if (ptr == NULL) {
        /* allocation failed */
    }

This lets you allocate a VLA on the heap.  It has the advantage that
you can easily use array notation to access elements of the VLA:

    (*ptr)[i][j]

without having to manage arrays of pointers, and you can test
whether the allocation succeeded.

(You can't do this in C++, but the standard library provides ways to do
similar things.)

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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


#19071

FromJuha Nieminen <nospam@thanks.invalid>
Date2012-10-19 09:30 +0000
Message-ID<k5r6ka$at5$3@speranza.aioe.org>
In reply to#19058
In comp.lang.c++ Keith Thompson <kst-u@mib.org> wrote:
> Which is true for *identifiers* defined as VLAs, but not for all VLAs:
> 
>    int x = /* whatever */;
>    int y = /* whatever */;
>    typedef double vla[x][y];
>    vla *ptr = malloc(sizeof *ptr);
>    if (ptr == NULL) {
>        /* allocation failed */
>    }

I don't think dynamically allocated arrays with malloc() are called
"variable length arrays". That term is quite specific and refers to
the new C99 feature where stack-allocated arrays do not need to have
a compile-time constant size.

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


#19075

FromKeith Thompson <kst-u@mib.org>
Date2012-10-19 03:05 -0700
Message-ID<lnd30eixp6.fsf@nuthaus.mib.org>
In reply to#19071
Juha Nieminen <nospam@thanks.invalid> writes:
> In comp.lang.c++ Keith Thompson <kst-u@mib.org> wrote:
>> Which is true for *identifiers* defined as VLAs, but not for all VLAs:
>> 
>>    int x = /* whatever */;
>>    int y = /* whatever */;
>>    typedef double vla[x][y];
>>    vla *ptr = malloc(sizeof *ptr);
>>    if (ptr == NULL) {
>>        /* allocation failed */
>>    }
>
> I don't think dynamically allocated arrays with malloc() are called
> "variable length arrays". That term is quite specific and refers to
> the new C99 feature where stack-allocated arrays do not need to have
> a compile-time constant size.

The type "vla" is a variable-length array type.  I happened to
allocate an object of that type via malloc(), rather than as a
declared object at block scope.  The type meets the definition of
"variable length array" in N1370 6.7.6.2p4.

Not all arrays allocated with malloc() are VLAs, only those of some
VLA type:

    typedef double not_a_vla[100];
    not_a_vla *ptr = malloc(sizeof *not_a_vla);

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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


#19080

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-10-19 07:37 -0400
Message-ID<k5re1c$d5c$1@dont-email.me>
In reply to#19071
On 10/19/2012 05:30 AM, Juha Nieminen wrote:
> In comp.lang.c++ Keith Thompson <kst-u@mib.org> wrote:
>> Which is true for *identifiers* defined as VLAs, but not for all VLAs:
>>
>>    int x = /* whatever */;
>>    int y = /* whatever */;
>>    typedef double vla[x][y];
>>    vla *ptr = malloc(sizeof *ptr);
>>    if (ptr == NULL) {
>>        /* allocation failed */
>>    }
> 
> I don't think dynamically allocated arrays with malloc() are called
> "variable length arrays". That term is quite specific and refers to
> the new C99 feature where stack-allocated arrays do not need to have
> a compile-time constant size.

<side_issue>The C standard doesn't talk about "stack-allocated". The
closest it comes is the term "automatic storage duration". I'll assume
that's what you're talking about. While the rules governing the
lifetimes of objects with automatic storage duration allow, and even
encourage, implementation using stack-like semantics, it's not mandatory
that they be allocated from the actual hardware stack (if there even is
one). For example, some real-world implementations implement those
semantics using activation records rather than a hardware
stack.</side_issue>

"... If an identifier is declared to be an object with static or thread
storage duration, it shall not have a variable length array type. ..."
(6.7.6.2p2). Only two of the four storage durations are prohibited by
that clause; both automatic and allocated storage durations are allowed.

"... If the size is * instead of being an expression, the array type is
a variable length array ... If the size is an integer constant
expression and the element type has a known constant size, the array
type is not a variable length array type; otherwise, the array type is a
variable length array type. ..." (6.7.6.2p4) The first and third
occurrences of "variable length array" in that citation are italicized,
indicating that those sentences together constitute the definition of
the term.

The type of *ptr is an array with a size of x, which is neither '*' nor
an integer constant expression. That alone would be enough to give *ptr
a variable length array type. However, the element type of that array is
also double[y], which does not have a known constant size, which would
therefore also be sufficient to make it a variable length array type.
ptr itself does NOT have a VLA type, it only points at one. It does,
however, have a variably modified (VM) type. There are no restrictions
on the storage duration of VM types, only of VLA types.
-- 
James Kuyper

[toc] | [prev] | [standalone]


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

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


csiph-web