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


Groups > comp.lang.c > #27254 > 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 20 on this page of 126 — 28 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" Ike Naar <ike@sverige.freeshell.org> - 2012-10-18 22:45 +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" 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" 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" 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" 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" 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" 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" 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" 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" 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 6 of 7 — ← Prev page 1 2 3 4 5 [6] 7  Next page →


#27447

FromJuha Nieminen <nospam@thanks.invalid>
Date2012-10-21 07:23 +0000
Message-ID<k607u8$jc9$1@speranza.aioe.org>
In reply to#27428
In comp.lang.c++ Fritz Wuehler <fritz@spamexpire-201210.rodent.frell.theremailer.net> wrote:
>> Also, C++ does have some features that are not offered by other languages.
> 
> This is hard to believe. Would you be inclined to name a few?

By "other languages" I was referring to the ones popularly used.

For example RAII *is* offered by some other languages (eg. if I remember
correctly ADA might have had it), but those tend to be either obscure
languages that nobody uses, or have fallen almost completely out of usage
in practice (except in very narrow and specific industries, eg. with ADA.)

(And no, this was not an argument on whether RAII is better than automatic
GC. That was not the point.)

It's hard to classify if any language offers the same functionality as
C++ templates do (regardless of what you think about their syntax; I'm
talking purely about the functionality here.) There are certainly some
languages (especially some functional ones) which you might argue offer
the same functionality, although using a rather different approach. But
even then there often are radical differences.

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


#27471

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2012-10-21 19:33 +0000
Message-ID<slrnk88jg3.1d3.grahn+nntp@frailea.sa.invalid>
In reply to#27316
On Thu, 2012-10-18, William Ahern wrote:
> In comp.lang.c Stuart <DerTopper@web.de> wrote:
>> On 10/18/12 James Kuyper wrote:
>> [snip]
>> > I'm primarily a C programmer, so I may be
>> > missing out some elegant C++ way of doing that, but the following
>> > inelegant (and untested) code should do the job:
>> [snip]
>
>> I'm intrigued. I have never ever met someone who described himself as a C
>> programmer. May I ask what kind of business you are in? My guess is your
>> line of work includes either device drivers, embedded devices, kernel code
>> or something else that forces you to write C instead of C++. In all these
>> years I have never met someone who used C instead of C++ unless he was
>> forced to do so.
>
> Well, you have now. I've worked in several shops (both small and billion
> dollar companies) which were C only by choice. The consensus was that the
> cost/benefit of C++ didn't pan out, particularly for backend, non-GUI work.

I've worked in those places too. Unlike you I believe they are
misguided, but I agree they exist and aren't unusual.

> I'm guessing that you come from a Windows background and/or graduated
> college in the past 3 or 4 years. That's usually how it goes, IME. C++
> didn't make waves in the Unix world until a few years ago, and then it took
> off with Google and Apple**, especially when they picked up their college
> recruitment. C++ grew up in Microsoft-land and in Microsoft-friendly
> universities which dumped SUN--or never had the history to begin with. Which
> isn't a slight, just an observation about the peculiarities of C++ culture.

I get the feeling (which may be incorrect) that you justify discarding
C++ by trying to associate it with Microsoft, and anti-Unix nonsense
in general.  Since I'm pro-Unix myself that annoys me.

There are /different/ C++ cultures, just like there are different C
cultures.  For me C++ fits very well into Unix programming[1]. It's
just like Unix programming in C, only with better tools such as the
standard containers, RAII and so on. I don't know what they do in the
Windows world ... seems to be most have spent many years down the
Java/.NET route until very recently.

/Jorgen

[1] One perhaps surprising reason is the Unix APIs are C API. That way
    I'm not tied to someone's antiquated ideas about how an
    object-oriented interface should work.  Sure, C APIs can feel
    primitive at times -- but at least a decent number of people know
    how do design them properly!

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .

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


#27473

FromGreg Martin <greg@softsprocket.com>
Date2012-10-21 13:20 -0700
Message-ID<rOYgs.16770$Ns2.2177@newsfe18.iad>
In reply to#27471
On 12-10-21 12:33 PM, Jorgen Grahn wrote:
> On Thu, 2012-10-18, William Ahern wrote:
>> In comp.lang.c Stuart <DerTopper@web.de> wrote:
>>> On 10/18/12 James Kuyper wrote:
>>> [snip]
>>>> I'm primarily a C programmer, so I may be
>>>> missing out some elegant C++ way of doing that, but the following
>>>> inelegant (and untested) code should do the job:
>>> [snip]
>>
>>> I'm intrigued. I have never ever met someone who described himself as a C
>>> programmer. May I ask what kind of business you are in? My guess is your
>>> line of work includes either device drivers, embedded devices, kernel code
>>> or something else that forces you to write C instead of C++. In all these
>>> years I have never met someone who used C instead of C++ unless he was
>>> forced to do so.
>>
>> Well, you have now. I've worked in several shops (both small and billion
>> dollar companies) which were C only by choice. The consensus was that the
>> cost/benefit of C++ didn't pan out, particularly for backend, non-GUI work.
>
> I've worked in those places too. Unlike you I believe they are
> misguided, but I agree they exist and aren't unusual.
>

What seems to be the real irony here is that it isn't 1992, though I'm 
getting a decided deja vu, but 2012 when this conversation should be 
taking place between C++ zealots and C# adherents (or maybe Java, 
Python, Ruby, erlang programmers et al).

I have worked on large scale projects in both C++ and C and prefer C 
however misguided you may feel that makes me. On the other hand there 
are projects for which I prefer to use other languages. C++ isn't on my 
goto list, pun intended.

Horse for courses I guess. I'm quite fond of erlang for instance though 
I don't believe you should learn it as I'm sure you can accomplish what 
you need to do in C++, however, there are a whole lot of things it does 
very well and with a fraction of the effort required by C++. Still, I 
don't suppose the sky will fall in on comp.lang.c++ any more then it has 
on comp.lang.c.

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


#27580

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2012-10-23 15:44 +0000
Message-ID<slrnk8dero.1d3.grahn+nntp@frailea.sa.invalid>
In reply to#27473
On Sun, 2012-10-21, Greg Martin wrote:
> On 12-10-21 12:33 PM, Jorgen Grahn wrote:
>> On Thu, 2012-10-18, William Ahern wrote:
>>> In comp.lang.c Stuart <DerTopper@web.de> wrote:
>>>> On 10/18/12 James Kuyper wrote:
>>>> [snip]
>>>>> I'm primarily a C programmer, so I may be
>>>>> missing out some elegant C++ way of doing that, but the following
>>>>> inelegant (and untested) code should do the job:
>>>> [snip]
>>>
>>>> I'm intrigued. I have never ever met someone who described himself as a C
>>>> programmer. May I ask what kind of business you are in? My guess is your
>>>> line of work includes either device drivers, embedded devices, kernel code
>>>> or something else that forces you to write C instead of C++. In all these
>>>> years I have never met someone who used C instead of C++ unless he was
>>>> forced to do so.
>>>
>>> Well, you have now. I've worked in several shops (both small and billion
>>> dollar companies) which were C only by choice. The consensus was that the
>>> cost/benefit of C++ didn't pan out, particularly for backend, non-GUI work.
>>
>> I've worked in those places too. Unlike you I believe they are
>> misguided, but I agree they exist and aren't unusual.
>>
>
> What seems to be the real irony here is that it isn't 1992, though I'm 
> getting a decided deja vu, but 2012 when this conversation should be 
> taking place between C++ zealots and C# adherents (or maybe Java, 
> Python, Ruby, erlang programmers et al).

I don't quite get your point here.  It's obviously not "C should have
died some time after 1992".

(For what it's worth, if I had a time machine I'd go back to 1992 and
tell people to stay off C++ for a few more years until the standard
library was in place, and templates widely understood. I have a
feeling many bad practices and much bad reputation came in that time
frame.)

> I have worked on large scale projects in both C++ and C and prefer C 
> however misguided you may feel that makes me.
...
> I'm quite fond of erlang for instance though 
> I don't believe you should learn it as I'm sure you can accomplish what 
> you need to do in C++

I just stated that I prefer C++ to C, not that C++ is better than all
other languages at everything!

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .

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


#27594

FromDombo <dombo@disposable.invalid>
Date2012-10-23 20:01 +0200
Message-ID<k66ltd$mv6$1@dont-email.me>
In reply to#27580
Op 23-Oct-12 17:44, Jorgen Grahn schreef:
> On Sun, 2012-10-21, Greg Martin wrote:

>> What seems to be the real irony here is that it isn't 1992, though I'm
>> getting a decided deja vu, but 2012 when this conversation should be
>> taking place between C++ zealots and C# adherents (or maybe Java,
>> Python, Ruby, erlang programmers et al).
>
> I don't quite get your point here.  It's obviously not "C should have
> died some time after 1992".
>
> (For what it's worth, if I had a time machine I'd go back to 1992 and
> tell people to stay off C++ for a few more years until the standard
> library was in place, and templates widely understood. I have a
> feeling many bad practices and much bad reputation came in that time
> frame.)

It would probably also have prevented many C++ libraries from 
implementing their own string and container classes. This is one thing I 
dislike about C++.

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


#27413

FromNick Keighley <nick_keighley_nospam@hotmail.com>
Date2012-10-20 06:13 -0700
Message-ID<6eb7c9a9-1241-4a14-901d-9900626db251@w2g2000vbc.googlegroups.com>
In reply to#27301
On Oct 18, 8:55 am, Stuart <DerTop...@web.de> wrote:
> On 10/18/12 James Kuyper wrote:
> [snip]> I'm primarily a C programmer, so I may be
> > missing out some elegant C++ way of doing that, but the following
> > inelegant (and untested) code should do the job:
>
> [snip]
>
> I'm intrigued. I have never ever met someone who described himself as a
> C programmer. May I ask what kind of business you are in? My guess is
> your line of work includes either device drivers, embedded devices,
> kernel code or something else that forces you to write C instead of C++.
> In all these years I have never met someone who used C instead of C++
> unless he was forced to do so.

seriously? I know quite a few people who are C programmers. Most are
embedded but not all.

I can see the appeal. I know pretty much all of C. I only know a large
percentage of C++. I haven't got round to the new C++ standard. I
don't know every little corner of the standard library and I certainly
don't know boost! Do you write exception safe code?

Please don't mention template-meta-programming...

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


#27448

FromJuha Nieminen <nospam@thanks.invalid>
Date2012-10-21 07:25 +0000
Message-ID<k60822$jc9$2@speranza.aioe.org>
In reply to#27413
In comp.lang.c++ Nick Keighley <nick_keighley_nospam@hotmail.com> wrote:
> I can see the appeal. I know pretty much all of C. I only know a large
> percentage of C++. I haven't got round to the new C++ standard. I
> don't know every little corner of the standard library and I certainly
> don't know boost! Do you write exception safe code?

That last question is really odd at the end of the paragraph that's
otherwise talking about something else entirely. Care to explain?

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


#27760

FromNick Keighley <nick_keighley_nospam@hotmail.com>
Date2012-10-27 05:54 -0700
Message-ID<2ab9be4f-397f-47b9-b71b-3225f805add3@y6g2000vbb.googlegroups.com>
In reply to#27448
On Oct 21, 8:25 am, Juha Nieminen <nos...@thanks.invalid> wrote:
> In comp.lang.c++ Nick Keighley <nick_keighley_nos...@hotmail.com> wrote:
>
> > I can see the appeal. I know pretty much all of C. I only know a large
> > percentage of C++. I haven't got round to the new C++ standard. I
> > don't know every little corner of the standard library and I certainly
> > don't know boost! Do you write exception safe code?
>
> That last question is really odd at the end of the paragraph that's
> otherwise talking about something else entirely. Care to explain?

I wondered how good a C++ programmer he was. I see a fair amount of C+
+ code that news multiple items and deletes them in the destructor.
That defines non-trivial destructors but not assignment or copy
construction. Code that sprinkles try-catch about seemingly at random.
Writing *good* C++ isn't hard but it requires some basic knowledge.

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


#28214

FromOld Wolf <oldwolf@inspire.net.nz>
Date2012-11-11 14:58 -0800
Message-ID<aef78c59-a4a2-43c0-b874-c507ecc83124@lg12g2000pbb.googlegroups.com>
In reply to#27301
On Oct 18, 8:55 pm, Stuart <DerTop...@web.de> wrote:
> I'm intrigued. I have never ever met someone who described himself as a
> C programmer. May I ask what kind of business you are in?

I describe myself as a C programmer too, and am
available to field questions :)

I write application code for payment terminals. You have to
use the toolset that the hardware vendor provides for
developing code that can interface with its OS, typically
this is some arcane modification of C with fairly stringent
memory requirements.


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


#28222

Fromgof@somewhere.invalid (Adam Wysocki)
Date2012-11-12 10:33 +0000
Message-ID<gof.1352716351.10919@somewhere.invalid>
In reply to#28214
In comp.lang.c Old Wolf <oldwolf@inspire.net.nz> wrote:

> I write application code for payment terminals.

What vendor and platform?

-- 
Gof
http://www.chmurka.net/

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


#27290

FromIan Collins <ian-news@hotmail.com>
Date2012-10-18 12:19 +1300
Message-ID<ae8sobFo8jlU7@mid.individual.net>
In reply to#27281
On 10/18/12 10:47, gus gassmann wrote:
>
>               myStruct = new MyStruct[ndim];
>               for (int i=0; i<  ndim; i++)
>               {
>                   myStruct[i] = {{(const)(get_str().c_str()), 0,
> get_int()}};
>               }

As others have correctly pointed out, the mistyped cast from std::string 
will end in tears.  You need to convert the string to an char array and 
keep track of that data for later disposal.

Something like this my help:

struct FromString
{
   static std::vector<char*> stash;

   char *p;

   FromString( const std::string& s )
     : p(new char[s.size()])
   {
     s.copy(p, s.size());
     stash.push_back(p);
   }

   operator char*() const { return p; }
};

std::vector<char*> FromString::stash;  // *free these later!!*

Then you could write:

   for (int i=0; i < ndim; i++)
   {
     MyStruct temp = {FromString(get_str()), 0, get_int()};
     myStruct[i] = temp;
   }

Note I kept the temporary variable to avoid the use C++11 extended 
initialiser lists.

-- 
Ian Collins

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


#27298

FromJuha Nieminen <nospam@thanks.invalid>
Date2012-10-18 07:06 +0000
Message-ID<k5o9q9$i1t$1@speranza.aioe.org>
In reply to#27257
In comp.lang.c++ Noob <root@127.0.0.1> wrote:
> If the size of the array is not known at compile-time, then you
> need dynamic memory allocation.

Incorrect. In C you can use a variable-length array, such as:

    void foo(int n)
    {
        SomeStruct s[n];
        ...
    }

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.

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


#27307

FromNoob <root@127.0.0.1>
Date2012-10-18 11:36 +0200
Message-ID<k5oiig$k8n$1@dont-email.me>
In reply to#27298
Juha Nieminen wrote:

> In comp.lang.c++ Noob wrote:
> 
>> If the size of the array is not known at compile-time, then you
>> need dynamic memory allocation.
> 
> Incorrect. In C you can use a variable-length array, such as:
> 
>     void foo(int n)
>     {
>         SomeStruct s[n];
>         ...
>     }

VLAs have automatic storage duration. They are therefore not appropriate
for the OP's purpose.

> 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."

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


#27341

FromJuha Nieminen <nospam@thanks.invalid>
Date2012-10-19 09:28 +0000
Message-ID<k5r6g5$at5$2@speranza.aioe.org>
In reply to#27307
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]


#27346

FromNoob <root@127.0.0.1>
Date2012-10-19 12:07 +0200
Message-ID<k5r8p6$g4d$1@dont-email.me>
In reply to#27341
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]


#27348

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#27346
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]


#27404

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#27348
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]


#27347

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-10-19 06:58 -0400
Message-ID<k5rbol$i7$1@dont-email.me>
In reply to#27341
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]


#27261

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-10-17 08:29 -0400
Message-ID<k5m8bb$fol$1@dont-email.me>
In reply to#27254
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]


#27262

FromRichard Damon <news.x.richarddamon@xoxy.net>
Date2012-10-17 08:35 -0400
Message-ID<k5m8ls$hvj$1@dont-email.me>
In reply to#27254
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]


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

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


csiph-web