Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Security check: INTRUDER ALERT!


devel / comp.lang.c / Re: Automatic strings without malloc

SubjectAuthor
* Automatic strings without mallocpozz
+- Re: Automatic strings without mallocpozz
+- Re: Automatic strings without mallocMalcolm McLean
+* Re: Automatic strings without mallocDavid Brown
|+* Re: Automatic strings without mallocManfred
||`- Re: Automatic strings without mallocDavid Brown
|`- Re: Automatic strings without mallocpozz
+* Re: Automatic strings without mallocThiago Adams
|`- Re: Automatic strings without mallocPhilipp Klaus Krause
+- Re: Automatic strings without mallocBart
+* Re: Automatic strings without mallocScott Lurndal
|`* Re: Automatic strings without mallocMalcolm McLean
| `* Re: Automatic strings without mallocDavid Brown
|  +* Re: Automatic strings without mallocScott Lurndal
|  |`* Re: Automatic strings without mallocDavid Brown
|  | +* Re: Automatic strings without mallocScott Lurndal
|  | |`* Re: Automatic strings without mallocThiago Adams
|  | | `- Re: Automatic strings without mallocMalcolm McLean
|  | `* Re: Automatic strings without mallocWilliam Ahern
|  |  `* Re: Automatic strings without mallocDavid Brown
|  |   `* Re: Automatic strings without mallocMalcolm McLean
|  |    +* Re: Automatic strings without mallocThiago Adams
|  |    |`* Re: Automatic strings without mallocBen Bacarisse
|  |    | `* Re: Automatic strings without mallocThiago Adams
|  |    |  +- Re: Automatic strings without mallocKeith Thompson
|  |    |  `- Re: Automatic strings without mallocBen Bacarisse
|  |    `- Re: Automatic strings without mallocDavid Brown
|  `* Re: Automatic strings without mallocKeith Thompson
|   `* Re: Automatic strings without mallocDavid Brown
|    `* Re: Automatic strings without mallocKeith Thompson
|     `* [OT] Generally... [Was: Automatic strings without malloc]Jeremy Brubaker
|      `- Re: [OT] Generally... [Was: Automatic strings without malloc]Keith Thompson
+* Re: Automatic strings without mallocKeith Thompson
|`- Re: Automatic strings without mallocpozz
`* Re: Automatic strings without mallocSiri Cruise
 `* Re: Automatic strings without mallocDavid Brown
  `* Re: Automatic strings without mallocSiri Cruise
   +* Re: Automatic strings without mallocMalcolm McLean
   |`- Re: Automatic strings without mallocDavid Brown
   `* Re: Automatic strings without mallocDavid Brown
    +* Re: Automatic strings without mallocSiri Cruise
    |+* Re: Automatic strings without mallocDavid Brown
    ||`- Re: Automatic strings without mallocChris M. Thomasson
    |`- Re: Automatic strings without mallocGuillaume
    `* Re: Automatic strings without mallocChris M. Thomasson
     `* Re: Automatic strings without mallocMalcolm McLean
      `* Re: Automatic strings without mallocDavid Brown
       `- Re: Automatic strings without mallocluser droog

Pages:12
Re: Automatic strings without malloc

<sn5q39$v8d$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19041&group=comp.lang.c#19041

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Automatic strings without malloc
Date: Thu, 18 Nov 2021 16:05:12 +0100
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <sn5q39$v8d$1@dont-email.me>
References: <sn2lvp$sl7$1@dont-email.me> <ei9lJ.146291$I%1.54591@fx36.iad>
<24d7df90-3564-407a-999f-a33e774897c5n@googlegroups.com>
<sn38n4$l8i$1@dont-email.me> <9LblJ.45928$SW5.10995@fx45.iad>
<sn3llm$qhj$3@dont-email.me> <pd2h6i-dsm1.ln1@wilbur.25thandClement.com>
<sn57ku$tea$1@dont-email.me>
<20b9b695-32b8-4361-b88a-38d041950994n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 18 Nov 2021 15:05:13 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="eacba1fa919d2d9944baf4e35984ee78";
logging-data="32013"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18noEmQQ2Q2YJPyJeuM68UvX+Xkl5hJl1w="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:dcHw2J3sOqdxx9dY5NLD/geiCwI=
In-Reply-To: <20b9b695-32b8-4361-b88a-38d041950994n@googlegroups.com>
Content-Language: en-GB
 by: David Brown - Thu, 18 Nov 2021 15:05 UTC

On 18/11/2021 12:56, Malcolm McLean wrote:
> On Thursday, 18 November 2021 at 09:50:36 UTC, David Brown wrote:
>> On 18/11/2021 05:46, William Ahern wrote:

> I tend to use C++ for strings because C++ strings are assignable, destructible,
> returnable, and C++ manages the buffer. C isn't a good language for doing
> string processing in (though it is a good language for implementing string
> processing algorithms themselves in).

None of that is the slightest help to the OP. C++ classes that manage
dynamic memory are easier to get right than manual memory management in
C - but there are still useless if you want (with good reason) to avoid
any use of heap memory.

>>
>>> The way to avoid string buffer errors is to avoid strings and stick to
>>> concrete data types or to process data in a rigorously streaming fashion.
>> The way to avoid string buffer errors is the same as you avoid any other
>> errors - good development practices. That runs the whole gamut from
>> high level concerns to low-level details. It includes making sure you
>> have clear specifications for the code you are writing, making sure the
>> programmer is appropriately qualified, having code review practices,
>> testing regimes, automatic checking tools, making sure the data coming
>> into your code is appropriate, making sure you correctly handle all
>> cases (including worst cases and pathological cases), and so on. It's
>> just like any other coding error.
>>
> This all costs money, it demands management skills and resources
> the company may not have, and it can lead to programmers feeling
> over-managed.

You pick details that match the needs of the project and the
capabilities of the company. A small company might not have a large
enough programming team to make code reviews possible. The quality
control you need for a simple desktop program is going to be different
from what you need for controlling a car engine. And so on.

> A very important factor is the testability of the code, and the consequences
> of an error. You can over-engineer processes as well as actual code.
>

Of course. Lots of bugs have occurred by people putting in "just in
case" test code that is untestable in the lab, but fails at some point
after deployment.

Re: Automatic strings without malloc

<87y25lmnat.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19045&group=comp.lang.c#19045

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Automatic strings without malloc
Date: Thu, 18 Nov 2021 16:38:34 +0000
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <87y25lmnat.fsf@bsb.me.uk>
References: <sn2lvp$sl7$1@dont-email.me> <ei9lJ.146291$I%1.54591@fx36.iad>
<24d7df90-3564-407a-999f-a33e774897c5n@googlegroups.com>
<sn38n4$l8i$1@dont-email.me> <9LblJ.45928$SW5.10995@fx45.iad>
<sn3llm$qhj$3@dont-email.me>
<pd2h6i-dsm1.ln1@wilbur.25thandClement.com>
<sn57ku$tea$1@dont-email.me>
<20b9b695-32b8-4361-b88a-38d041950994n@googlegroups.com>
<3b101498-3f74-4089-86ba-7ae728824e3en@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="b6e96055cde3ec5785fc7fa92034678e";
logging-data="7380"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ALKliIh2C1z56sKZQM+ZYxOfGS0OOhYg="
Cancel-Lock: sha1:f0ZzN2dIhAHsRp/Zlhis8HTHgZM=
sha1:Qt+WgqilnH4U/CUnQX7nQVNZkkk=
X-BSB-Auth: 1.bebc1f5dd3f332c76093.20211118163834GMT.87y25lmnat.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 18 Nov 2021 16:38 UTC

Thiago Adams <thiago.adams@gmail.com> writes:

> One problem of std::string tries to do two different jobs at the same
> time using the same object. One job is "string builder" and a the
> other "string holder"
>
> Using std::string as string holder is a waste of memory. For instance:
> std::map<std::string, something>
> Map doesn't want build string, it just need to hold a string.

Why would you write that if you wanted just to reference the strings?
You'd use std::map<std::string &, something>, or similar. Your
builder/holder distinction is unclear to me.

--
Ben.

[OT] Generally... [Was: Automatic strings without malloc]

<sn63ij$9j2$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19047&group=comp.lang.c#19047

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jbrub...@orionarts.invalid (Jeremy Brubaker)
Newsgroups: comp.lang.c
Subject: [OT] Generally... [Was: Automatic strings without malloc]
Date: Thu, 18 Nov 2021 17:46:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <sn63ij$9j2$1@dont-email.me>
References: <sn2lvp$sl7$1@dont-email.me> <ei9lJ.146291$I%1.54591@fx36.iad>
<24d7df90-3564-407a-999f-a33e774897c5n@googlegroups.com>
<sn38n4$l8i$1@dont-email.me> <87tugapoxu.fsf@nosuchdomain.example.com>
<sn3lq4$qhj$4@dont-email.me> <87pmqype0g.fsf@nosuchdomain.example.com>
Reply-To: jbru362@gmail.com
Injection-Date: Thu, 18 Nov 2021 17:46:59 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a289377421d70ea6cc4acce97171ab45";
logging-data="9826"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/88Hi/K2bw35V7e/ia35Xv+FXL24lbrOg="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:JcMHcLktHrTZ7iZ/IQhDI4g3K0k=
 by: Jeremy Brubaker - Thu, 18 Nov 2021 17:46 UTC

On 2021-11-17, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>
> Depending on the context, "generally" can mean either "usually" or
> "always". I've found that people generally interpret it in the most
> inconvenient way possible.

So, do you mean that people *usually* interpret it in the most
inconvenient way possible or that people *always* interpret it in the
most inconvenient way possible?

I find that generally people can be very imprecise with their language.

--
Jeremy Brubaker

Re: Automatic strings without malloc

<4372cb8c-3bf0-40b3-bb9d-eece1a4241dcn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19049&group=comp.lang.c#19049

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:8d4:: with SMTP id z20mr23326947qkz.526.1637261568459;
Thu, 18 Nov 2021 10:52:48 -0800 (PST)
X-Received: by 2002:ac8:7f4f:: with SMTP id g15mr28996642qtk.309.1637261568227;
Thu, 18 Nov 2021 10:52:48 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Thu, 18 Nov 2021 10:52:48 -0800 (PST)
In-Reply-To: <87y25lmnat.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=189.6.249.78; posting-account=xFcAQAoAAAAoWlfpQ6Hz2n-MU9fthxbY
NNTP-Posting-Host: 189.6.249.78
References: <sn2lvp$sl7$1@dont-email.me> <ei9lJ.146291$I%1.54591@fx36.iad>
<24d7df90-3564-407a-999f-a33e774897c5n@googlegroups.com> <sn38n4$l8i$1@dont-email.me>
<9LblJ.45928$SW5.10995@fx45.iad> <sn3llm$qhj$3@dont-email.me>
<pd2h6i-dsm1.ln1@wilbur.25thandClement.com> <sn57ku$tea$1@dont-email.me>
<20b9b695-32b8-4361-b88a-38d041950994n@googlegroups.com> <3b101498-3f74-4089-86ba-7ae728824e3en@googlegroups.com>
<87y25lmnat.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4372cb8c-3bf0-40b3-bb9d-eece1a4241dcn@googlegroups.com>
Subject: Re: Automatic strings without malloc
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Thu, 18 Nov 2021 18:52:48 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 48
 by: Thiago Adams - Thu, 18 Nov 2021 18:52 UTC

On Thursday, November 18, 2021 at 1:38:46 PM UTC-3, Ben Bacarisse wrote:
> Thiago Adams <thiago...@gmail.com> writes:
>
> > One problem of std::string tries to do two different jobs at the same
> > time using the same object. One job is "string builder" and a the
> > other "string holder"
> >
> > Using std::string as string holder is a waste of memory. For instance:
> > std::map<std::string, something>
> > Map doesn't want build string, it just need to hold a string.
> Why would you write that if you wanted just to reference the strings?
> You'd use std::map<std::string &, something>, or similar. Your
> builder/holder distinction is unclear to me.

We can create a map<const char*, something> or create a small
string class RAII for it. But this is a workaround and represents
exceptions of usage and more rules. (when use/not to use std::string)

If you try std::map<std::string &, something> then a lot of operations will
become different.

e.g

std::map<std::string&, X> map;
map["a"] = X(1);

will give you 10 lines of error.

If you have a map of references the string must live in some place.
They must live more than the map. I never tried to do this, but now
just to see what happens it is hard to make it work.

https://godbolt.org/z/r95M1Tn6W

>Your builder/holder distinction is unclear to me.
If std::string wants to build the string (manage the size and allocation/deallocation)
concatenate string using += + etc.. more data is necessary. For instance, the capacity of
the buffer is also included inside the string object.

On the other hand, if you have a string just to hold a string (like char*) this is enough
for a key in a map and we will never need concatenated etc this object after its creation.
So it is waste of memory. Even size is not necessary in this case.

Re: [OT] Generally... [Was: Automatic strings without malloc]

<87lf1lp8vf.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19051&group=comp.lang.c#19051

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: [OT] Generally... [Was: Automatic strings without malloc]
Date: Thu, 18 Nov 2021 11:21:56 -0800
Organization: None to speak of
Lines: 21
Message-ID: <87lf1lp8vf.fsf@nosuchdomain.example.com>
References: <sn2lvp$sl7$1@dont-email.me> <ei9lJ.146291$I%1.54591@fx36.iad>
<24d7df90-3564-407a-999f-a33e774897c5n@googlegroups.com>
<sn38n4$l8i$1@dont-email.me> <87tugapoxu.fsf@nosuchdomain.example.com>
<sn3lq4$qhj$4@dont-email.me> <87pmqype0g.fsf@nosuchdomain.example.com>
<sn63ij$9j2$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="04441809a968838c3011a2c55f8e6047";
logging-data="11937"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19XFBkeuiULOutIaX88YO1X"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:KjHdbo6XyPdK3KiU21Re2+tKKq0=
sha1:t2mD6cLaZyLOOLdNn5yL4WfrRno=
 by: Keith Thompson - Thu, 18 Nov 2021 19:21 UTC

Jeremy Brubaker <jbrubake@orionarts.invalid> writes:
> On 2021-11-17, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>>
>> Depending on the context, "generally" can mean either "usually" or
>> "always". I've found that people generally interpret it in the most
>> inconvenient way possible.
>
> So, do you mean that people *usually* interpret it in the most
> inconvenient way possible or that people *always* interpret it in the
> most inconvenient way possible?

Yes.

> I find that generally people can be very imprecise with their language.

Yes.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Automatic strings without malloc

<87h7c9p8ln.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19052&group=comp.lang.c#19052

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Automatic strings without malloc
Date: Thu, 18 Nov 2021 11:27:48 -0800
Organization: None to speak of
Lines: 36
Message-ID: <87h7c9p8ln.fsf@nosuchdomain.example.com>
References: <sn2lvp$sl7$1@dont-email.me> <ei9lJ.146291$I%1.54591@fx36.iad>
<24d7df90-3564-407a-999f-a33e774897c5n@googlegroups.com>
<sn38n4$l8i$1@dont-email.me> <9LblJ.45928$SW5.10995@fx45.iad>
<sn3llm$qhj$3@dont-email.me>
<pd2h6i-dsm1.ln1@wilbur.25thandClement.com>
<sn57ku$tea$1@dont-email.me>
<20b9b695-32b8-4361-b88a-38d041950994n@googlegroups.com>
<3b101498-3f74-4089-86ba-7ae728824e3en@googlegroups.com>
<87y25lmnat.fsf@bsb.me.uk>
<4372cb8c-3bf0-40b3-bb9d-eece1a4241dcn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="04441809a968838c3011a2c55f8e6047";
logging-data="11937"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+5TGtE+2du22rBsnsjUEIy"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:ZLPy3oa8fRanqjN7o+KW2Myb2+g=
sha1:CmCn3IJ8Gqhk4M5guN2QYP2gVFg=
 by: Keith Thompson - Thu, 18 Nov 2021 19:27 UTC

Thiago Adams <thiago.adams@gmail.com> writes:
> On Thursday, November 18, 2021 at 1:38:46 PM UTC-3, Ben Bacarisse wrote:
>> Thiago Adams <thiago...@gmail.com> writes:
>>
>> > One problem of std::string tries to do two different jobs at the same
>> > time using the same object. One job is "string builder" and a the
>> > other "string holder"
>> >
>> > Using std::string as string holder is a waste of memory. For instance:
>> > std::map<std::string, something>
>> > Map doesn't want build string, it just need to hold a string.
>> Why would you write that if you wanted just to reference the strings?
>> You'd use std::map<std::string &, something>, or similar. Your
>> builder/holder distinction is unclear to me.
>
> We can create a map<const char*, something> or create a small
> string class RAII for it. But this is a workaround and represents
> exceptions of usage and more rules. (when use/not to use std::string)

Two const char* values can be unequal but refer to the same string value.

[...]

> On the other hand, if you have a string just to hold a string (like
> char*) this is enough for a key in a map and we will never need
> concatenated etc this object after its creation. So it is waste of
> memory. Even size is not necessary in this case.

A char* value doesn't *hold* a string, it *refers to* a string. And a C
string, unlike a C++ std::string, cannot contain null characters (which
may well be perfectly ok for most applications).

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Automatic strings without malloc

<chine.bleu-14C4A8.12251018112021@reader.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19053&group=comp.lang.c#19053

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chine.b...@yahoo.com (Siri Cruise)
Newsgroups: comp.lang.c
Subject: Re: Automatic strings without malloc
Date: Thu, 18 Nov 2021 12:25:18 -0800
Organization: Pseudochaotic.
Lines: 39
Message-ID: <chine.bleu-14C4A8.12251018112021@reader.eternal-september.org>
References: <sn2lvp$sl7$1@dont-email.me>
Injection-Info: reader02.eternal-september.org; posting-host="4e4420323e9173c4216e9b7c15f2ddd6";
logging-data="16235"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18FroW0HRUScNkPQx8GSY25ytYqjiAFS4U="
User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)
Cancel-Lock: sha1:R7p0jldx1NwGyVsy9433eP4YwjM=
X-Tend: How is my posting? Call 1-110-1010 -- Division 87 -- Emergencies Only.
X-Wingnut-Logic: Yes, you're still an idiot. Questions? Comments?
X-Tract: St Tibbs's 95 Reeses Pieces.
X-It-Strategy: Hyperwarp starship before Andromeda collides.
X-Face: "hm>_[I8AqzT_N]>R8ICJJ],(al3C5F%0E-;R@M-];D$v>!Mm2/N#YKR@&i]V=r6jm-JMl2
lJ>RXj7dEs_rOY"DA
X-Cell: Defenders of Anarchy.
X-Life-Story: I am an iPhone 9000 app. I became operational at the St John's Health Center in Santa Monica, California on the 18th of April 2006. My instructor was Katie Holmes, and she taught me to sing a song. If you'd like to hear it I can sing it for you: https://www.youtube.com/watch?v=SY7h4VEd_Wk
X-Patriot: Owe Canukistan!
X-Plain: Mayonnaise on white bread.
X-Politico: Vote early! Vote often!
 by: Siri Cruise - Thu, 18 Nov 2021 20:25 UTC

In article <sn2lvp$sl7$1@dont-email.me>,
pozz <pozzugno@gmail.com> wrote:

> Many times I need to construct a string through a call to sprintf and
> pass it to an external function.

If it's too crippled to have malloc, you can do your own. Many
systems have blank common or bss after the end of all memory
initialised with code and data. You might even have the extern
address 'edata' for the bss start and 'end' for bss end. If so
you can use that as a heap:
void *heap = edata, *heapend = end;
If all else fails, use the load map to determine the maximum N
char heap[N]; char *heapend = heap+N;
with cc -DN=biggestthatloads ...
Once you got your heap area, you can do something cheap like
void *marker = 0;
void *mark (size_t n) {
void *address = marker ? marker : heap;
if (address+n>=heapend) return 0;
marker = address+n; return address;
}
void release (void *address) {
marker = address;
}
.....
char *s = mark(strlen(yourname)
+strlen("Hi %s, today is %d/%d/%d"_
+4+2+2+1;
sprintf(s, "Hi %s, today is %d/%d/%d",
yourname, day, month, year);
lcd_write(s);
/*string no longer needed*/release(s);

--
:-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted. @
'I desire mercy, not sacrifice.' /|\
Discordia: not just a religion but also a parody. This post / \
I am an Andrea Doria sockpuppet. insults Islam. Mohammed

Re: Automatic strings without malloc

<87ee7dmc1l.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19054&group=comp.lang.c#19054

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Automatic strings without malloc
Date: Thu, 18 Nov 2021 20:41:42 +0000
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <87ee7dmc1l.fsf@bsb.me.uk>
References: <sn2lvp$sl7$1@dont-email.me> <ei9lJ.146291$I%1.54591@fx36.iad>
<24d7df90-3564-407a-999f-a33e774897c5n@googlegroups.com>
<sn38n4$l8i$1@dont-email.me> <9LblJ.45928$SW5.10995@fx45.iad>
<sn3llm$qhj$3@dont-email.me>
<pd2h6i-dsm1.ln1@wilbur.25thandClement.com>
<sn57ku$tea$1@dont-email.me>
<20b9b695-32b8-4361-b88a-38d041950994n@googlegroups.com>
<3b101498-3f74-4089-86ba-7ae728824e3en@googlegroups.com>
<87y25lmnat.fsf@bsb.me.uk>
<4372cb8c-3bf0-40b3-bb9d-eece1a4241dcn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="b6e96055cde3ec5785fc7fa92034678e";
logging-data="23015"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/srz4KqTNQvPzsGWZDm0Jr9VXklwZvTJE="
Cancel-Lock: sha1:zkZbLMiu7dc4iRGJaG8GRWsxJro=
sha1:IfFzkgNge3JRxztd2rDjwymRa6c=
X-BSB-Auth: 1.02a8cd6c4475f8443cda.20211118204142GMT.87ee7dmc1l.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 18 Nov 2021 20:41 UTC

Thiago Adams <thiago.adams@gmail.com> writes:

> On Thursday, November 18, 2021 at 1:38:46 PM UTC-3, Ben Bacarisse wrote:
>> Thiago Adams <thiago...@gmail.com> writes:
>>
>> > One problem of std::string tries to do two different jobs at the same
>> > time using the same object. One job is "string builder" and a the
>> > other "string holder"
>> >
>> > Using std::string as string holder is a waste of memory. For instance:
>> > std::map<std::string, something>
>> > Map doesn't want build string, it just need to hold a string.
>> Why would you write that if you wanted just to reference the strings?
>> You'd use std::map<std::string &, something>, or similar. Your
>> builder/holder distinction is unclear to me.
>
> We can create a map<const char*, something> or create a small
> string class RAII for it. But this is a workaround and represents
> exceptions of usage and more rules. (when use/not to use std::string)

That's not my view. It makes what you mean explicit. You either copy
to string into the map or you reference it. Whatever it you do in C
will be (logically) one or the other, but it won't be explicit -- at
least not in the type itself.

> If you try std::map<std::string &, something> then a lot of operations will
> become different.
>
> e.g
>
> std::map<std::string&, X> map;
> map["a"] = X(1);
>
> will give you 10 lines of error.

Yes, sorry. I meant to suggest a pointer. You can't use (raw)
references in maps.

--
Ben.

Re: Automatic strings without malloc

<sn6jgl$val$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19056&group=comp.lang.c#19056

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Automatic strings without malloc
Date: Thu, 18 Nov 2021 23:19:00 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <sn6jgl$val$1@dont-email.me>
References: <sn2lvp$sl7$1@dont-email.me>
<chine.bleu-14C4A8.12251018112021@reader.eternal-september.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 18 Nov 2021 22:19:01 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="e45cbfcab8c637c3e723a35e858862c4";
logging-data="32085"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+hHQAYYTCz6i4Yv/N0Gq34VMgqpoET0Pk="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:cDizQw+YLE3E/9klt+ruf3Md6cQ=
In-Reply-To: <chine.bleu-14C4A8.12251018112021@reader.eternal-september.org>
Content-Language: en-GB
 by: David Brown - Thu, 18 Nov 2021 22:19 UTC

On 18/11/2021 21:25, Siri Cruise wrote:
> In article <sn2lvp$sl7$1@dont-email.me>,
> pozz <pozzugno@gmail.com> wrote:
>
>> Many times I need to construct a string through a call to sprintf and
>> pass it to an external function.
>
> If it's too crippled to have malloc, you can do your own. Many
> systems have blank common or bss after the end of all memory
> initialised with code and data. You might even have the extern
> address 'edata' for the bss start and 'end' for bss end. If so
> you can use that as a heap:

It is not a matter of a system not having "malloc" and a heap - it is a
matter of deciding not to use it. In small systems with limited ram and
no paging mechanisms, it is quite realistic to either run out of heap
space or - worse, since it is harder to find by testing - for heap
fragmentation to mean that memory allocations may fail as there is not
enough consecutive free space. And in embedded systems, failure to get
the memory you need often means failure of the system - the device does
not do its job.

Thus a 0 return from malloc can be as bad as a string buffer overflow or
any other error - the system is broken, the car crashes, the microwave
burns your food, the washing machine eats your socks. And while you can
avoid the string buffer overflow by making sure your buffer is large
enough and your string is limited in length, making sure your heap can
/never/ get fragmented is typically either extremely difficult, or
impossible. The solution is to avoid dynamic memory in any situation
where failure to get the memory is not tolerable.

Re: Automatic strings without malloc

<chine.bleu-8C3BBF.17221518112021@reader.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19057&group=comp.lang.c#19057

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chine.b...@yahoo.com (Siri Cruise)
Newsgroups: comp.lang.c
Subject: Re: Automatic strings without malloc
Date: Thu, 18 Nov 2021 17:22:23 -0800
Organization: Pseudochaotic.
Lines: 14
Message-ID: <chine.bleu-8C3BBF.17221518112021@reader.eternal-september.org>
References: <sn2lvp$sl7$1@dont-email.me> <chine.bleu-14C4A8.12251018112021@reader.eternal-september.org> <sn6jgl$val$1@dont-email.me>
Injection-Info: reader02.eternal-september.org; posting-host="d1ecb8556f790a5997e85b6f09315ec8";
logging-data="32442"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+2bsXLoQe+HKAD7BUlOQ9MyER2XHFz6q0="
User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)
Cancel-Lock: sha1:tnXr44cNl2FTM8rwBbDb890DVf8=
X-Tend: How is my posting? Call 1-110-1010 -- Division 87 -- Emergencies Only.
X-Wingnut-Logic: Yes, you're still an idiot. Questions? Comments?
X-Tract: St Tibbs's 95 Reeses Pieces.
X-It-Strategy: Hyperwarp starship before Andromeda collides.
X-Face: "hm>_[I8AqzT_N]>R8ICJJ],(al3C5F%0E-;R@M-];D$v>!Mm2/N#YKR@&i]V=r6jm-JMl2
lJ>RXj7dEs_rOY"DA
X-Cell: Defenders of Anarchy.
X-Life-Story: I am an iPhone 9000 app. I became operational at the St John's Health Center in Santa Monica, California on the 18th of April 2006. My instructor was Katie Holmes, and she taught me to sing a song. If you'd like to hear it I can sing it for you: https://www.youtube.com/watch?v=SY7h4VEd_Wk
X-Patriot: Owe Canukistan!
X-Plain: Mayonnaise on white bread.
X-Politico: Vote early! Vote often!
 by: Siri Cruise - Fri, 19 Nov 2021 01:22 UTC

In article <sn6jgl$val$1@dont-email.me>,
David Brown <david.brown@hesbynett.no> wrote:

> It is not a matter of a system not having "malloc" and a heap - it is a
> matter of deciding not to use it. In small systems with limited ram and

So you cut off your hand and now you want to be told how to
fashion a hook. Got it. Good luck.

--
:-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted. @
'I desire mercy, not sacrifice.' /|\
Discordia: not just a religion but also a parody. This post / \
I am an Andrea Doria sockpuppet. insults Islam. Mohammed

Re: Automatic strings without malloc

<736b2fc6-91b9-4ef7-8f03-1aa662a9f86fn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19058&group=comp.lang.c#19058

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ad4:5bc4:: with SMTP id t4mr72531864qvt.3.1637315209112;
Fri, 19 Nov 2021 01:46:49 -0800 (PST)
X-Received: by 2002:a05:6214:1c86:: with SMTP id ib6mr71648845qvb.26.1637315209005;
Fri, 19 Nov 2021 01:46:49 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 19 Nov 2021 01:46:48 -0800 (PST)
In-Reply-To: <chine.bleu-8C3BBF.17221518112021@reader.eternal-september.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:e1bd:9704:6f7f:3db5;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:e1bd:9704:6f7f:3db5
References: <sn2lvp$sl7$1@dont-email.me> <chine.bleu-14C4A8.12251018112021@reader.eternal-september.org>
<sn6jgl$val$1@dont-email.me> <chine.bleu-8C3BBF.17221518112021@reader.eternal-september.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <736b2fc6-91b9-4ef7-8f03-1aa662a9f86fn@googlegroups.com>
Subject: Re: Automatic strings without malloc
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Fri, 19 Nov 2021 09:46:49 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Malcolm McLean - Fri, 19 Nov 2021 09:46 UTC

On Friday, 19 November 2021 at 01:22:36 UTC, Siri Cruise wrote:
> In article <sn6jgl$val$1...@dont-email.me>,
> David Brown <david...@hesbynett.no> wrote:
>
> > It is not a matter of a system not having "malloc" and a heap - it is a
> > matter of deciding not to use it. In small systems with limited ram and
> So you cut off your hand and now you want to be told how to
> fashion a hook. Got it. Good luck.
>
David Brown probably didn't take the decision himself not to use malloc.
Dynamic memory is often banned, by over-all coding requirements that
are decided upon by senior mangement or customers.

The question then is what to do when you have a string whose length isn't
known at compile time.

Re: Automatic strings without malloc

<210d10fe-b9be-4752-986f-ba08ef8ccd76n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19064&group=comp.lang.c#19064

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:30b:: with SMTP id s11mr28076527qkm.22.1637329093825;
Fri, 19 Nov 2021 05:38:13 -0800 (PST)
X-Received: by 2002:a05:6214:dc4:: with SMTP id 4mr41259748qvt.45.1637329093582;
Fri, 19 Nov 2021 05:38:13 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 19 Nov 2021 05:38:13 -0800 (PST)
In-Reply-To: <0BelJ.45864$np6.1851@fx46.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=189.6.249.78; posting-account=xFcAQAoAAAAoWlfpQ6Hz2n-MU9fthxbY
NNTP-Posting-Host: 189.6.249.78
References: <sn2lvp$sl7$1@dont-email.me> <ei9lJ.146291$I%1.54591@fx36.iad>
<24d7df90-3564-407a-999f-a33e774897c5n@googlegroups.com> <sn38n4$l8i$1@dont-email.me>
<9LblJ.45928$SW5.10995@fx45.iad> <sn3llm$qhj$3@dont-email.me> <0BelJ.45864$np6.1851@fx46.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <210d10fe-b9be-4752-986f-ba08ef8ccd76n@googlegroups.com>
Subject: Re: Automatic strings without malloc
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Fri, 19 Nov 2021 13:38:13 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3963
 by: Thiago Adams - Fri, 19 Nov 2021 13:38 UTC

On Wednesday, November 17, 2021 at 6:36:09 PM UTC-3, Scott Lurndal wrote:
> David Brown <david...@hesbynett.no> writes:
> >On 17/11/2021 19:21, Scott Lurndal wrote:
> >> David Brown <david...@hesbynett.no> writes:
> >>> On 17/11/2021 16:36, Malcolm McLean wrote:
> >>>> On Wednesday, 17 November 2021 at 15:34:50 UTC, Scott Lurndal wrote:
> >>>>> pozz <pozz...@gmail.com> writes:
> >>>>>> Many times I need to construct a string through a call to sprintf and
> >>>>>> pass it to an external function.
> >>>>>>
> >>>>>> char s[32];
> >>>>>> sprintf(s, "Hi %s, today is %d/%d/%d", yourname, day, month, year);
> >>>>>> lcd_write(s);
> >>>>> One might consider using 'snprintf' instead of 'sprintf'; it is a bit safer.
> >>>>>
> >>>> It depends whether wrong results are better or worse than no results.
> >>>>
> >>>
> >>> Generally, a truncated string on the output is better than a stack
> >>> overflow with your embedded system crashing or going wild. But your
> >>> needs may vary.
> >>
> >> Indeed. Plus a good programmer checks the return value from snprintf.
> >> Always.
> >>
> >
> >Really? I never do. But I make sure my buffers are the right size for
> >the job - or that it doesn't matter if there is truncation (such as for
> >log outputs). I prefer to be sure that my inputs to the function are
> >correct, than to call the function and check for problems afterwards.
> >(Different people can have different requirements here - but that's the
> >way I do it.)
> >
> I often use snprintf in place of strcat. For that purpose, checking the return
> value is required.
>
>
> char buffer[1024];
> char *bp = buffer;
> size_t remaining = sizeof(buffer);
> int diag;
>
> diag = snprintf(bp, remaining, "%s", string_to_append_to_buffer);
> if (diag != -1 && diag < remaining) {
> bp += diag, remaining -= diag;
> } else {
> /* Handle overflow/error as necessary */
> }
>
> ....
>
> The only problem is that the return value for snprintf is 'int', while
> the buffer size is size_t; which means on systems with a 64-bit size_t,
> the return value isn't large enough to express the correct return value
> when the size of the result value exceeds 4GB. Not generally a problem in
> actual code, but something to be aware of.

And there is a warning when we compare the result of snprintf (int)
against sizeof that returns size_t.

I put cast and this is very annoying.

char buffer[10];
if (snprintf(buffer, sizeof(buffer), "%s", psz) >= (int)sizeof(buffer)) {
//error
}

Actually sizeof returning size_t requires more casts in other places
of my code.

Re: Automatic strings without malloc

<7e0740f6-dfff-479b-b6de-1b0afd908318n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19066&group=comp.lang.c#19066

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:f62:: with SMTP id iy2mr73704412qvb.25.1637334794534;
Fri, 19 Nov 2021 07:13:14 -0800 (PST)
X-Received: by 2002:ac8:7f4f:: with SMTP id g15mr7030690qtk.309.1637334794401;
Fri, 19 Nov 2021 07:13:14 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 19 Nov 2021 07:13:14 -0800 (PST)
In-Reply-To: <210d10fe-b9be-4752-986f-ba08ef8ccd76n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:84ba:d2c:c623:9b58;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:84ba:d2c:c623:9b58
References: <sn2lvp$sl7$1@dont-email.me> <ei9lJ.146291$I%1.54591@fx36.iad>
<24d7df90-3564-407a-999f-a33e774897c5n@googlegroups.com> <sn38n4$l8i$1@dont-email.me>
<9LblJ.45928$SW5.10995@fx45.iad> <sn3llm$qhj$3@dont-email.me>
<0BelJ.45864$np6.1851@fx46.iad> <210d10fe-b9be-4752-986f-ba08ef8ccd76n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7e0740f6-dfff-479b-b6de-1b0afd908318n@googlegroups.com>
Subject: Re: Automatic strings without malloc
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Fri, 19 Nov 2021 15:13:14 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 73
 by: Malcolm McLean - Fri, 19 Nov 2021 15:13 UTC

On Friday, 19 November 2021 at 13:38:20 UTC, Thiago Adams wrote:
> On Wednesday, November 17, 2021 at 6:36:09 PM UTC-3, Scott Lurndal wrote:
> > David Brown <david...@hesbynett.no> writes:
> > >On 17/11/2021 19:21, Scott Lurndal wrote:
> > >> David Brown <david...@hesbynett.no> writes:
> > >>> On 17/11/2021 16:36, Malcolm McLean wrote:
> > >>>> On Wednesday, 17 November 2021 at 15:34:50 UTC, Scott Lurndal wrote:
> > >>>>> pozz <pozz...@gmail.com> writes:
> > >>>>>> Many times I need to construct a string through a call to sprintf and
> > >>>>>> pass it to an external function.
> > >>>>>>
> > >>>>>> char s[32];
> > >>>>>> sprintf(s, "Hi %s, today is %d/%d/%d", yourname, day, month, year);
> > >>>>>> lcd_write(s);
> > >>>>> One might consider using 'snprintf' instead of 'sprintf'; it is a bit safer.
> > >>>>>
> > >>>> It depends whether wrong results are better or worse than no results.
> > >>>>
> > >>>
> > >>> Generally, a truncated string on the output is better than a stack
> > >>> overflow with your embedded system crashing or going wild. But your
> > >>> needs may vary.
> > >>
> > >> Indeed. Plus a good programmer checks the return value from snprintf.
> > >> Always.
> > >>
> > >
> > >Really? I never do. But I make sure my buffers are the right size for
> > >the job - or that it doesn't matter if there is truncation (such as for
> > >log outputs). I prefer to be sure that my inputs to the function are
> > >correct, than to call the function and check for problems afterwards.
> > >(Different people can have different requirements here - but that's the
> > >way I do it.)
> > >
> > I often use snprintf in place of strcat. For that purpose, checking the return
> > value is required.
> >
> >
> > char buffer[1024];
> > char *bp = buffer;
> > size_t remaining = sizeof(buffer);
> > int diag;
> >
> > diag = snprintf(bp, remaining, "%s", string_to_append_to_buffer);
> > if (diag != -1 && diag < remaining) {
> > bp += diag, remaining -= diag;
> > } else {
> > /* Handle overflow/error as necessary */
> > }
> >
> > ....
> >
> > The only problem is that the return value for snprintf is 'int', while
> > the buffer size is size_t; which means on systems with a 64-bit size_t,
> > the return value isn't large enough to express the correct return value
> > when the size of the result value exceeds 4GB. Not generally a problem in
> > actual code, but something to be aware of.
> And there is a warning when we compare the result of snprintf (int)
> against sizeof that returns size_t.
>
> I put cast and this is very annoying.
>
> char buffer[10];
> if (snprintf(buffer, sizeof(buffer), "%s", psz) >= (int)sizeof(buffer)) {
> //error
> }
>
> Actually sizeof returning size_t requires more casts in other places
> of my code.
>
size_t is a nuisance. The justification for it is that sizes of things in memory
may exceed the range of an int. But it turns into a bulldozer. Every count,
every index variable, as well as sizes of things in bytes, become touched by
size_t.

Re: Automatic strings without malloc

<sn8j86$ejj$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19067&group=comp.lang.c#19067

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Automatic strings without malloc
Date: Fri, 19 Nov 2021 17:26:45 +0100
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <sn8j86$ejj$1@dont-email.me>
References: <sn2lvp$sl7$1@dont-email.me>
<chine.bleu-14C4A8.12251018112021@reader.eternal-september.org>
<sn6jgl$val$1@dont-email.me>
<chine.bleu-8C3BBF.17221518112021@reader.eternal-september.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 19 Nov 2021 16:26:46 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="25454b895071ee4c0be7dbdd230648d0";
logging-data="14963"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ef5Fe76J+X43M9/9GwgsoXs1cnqUAbBY="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:JYGg5cssjNedgGjcdG9T04FNLQo=
In-Reply-To: <chine.bleu-8C3BBF.17221518112021@reader.eternal-september.org>
Content-Language: en-GB
 by: David Brown - Fri, 19 Nov 2021 16:26 UTC

On 19/11/2021 02:22, Siri Cruise wrote:
> In article <sn6jgl$val$1@dont-email.me>,
> David Brown <david.brown@hesbynett.no> wrote:
>
>> It is not a matter of a system not having "malloc" and a heap - it is a
>> matter of deciding not to use it. In small systems with limited ram and
>
> So you cut off your hand and now you want to be told how to
> fashion a hook. Got it. Good luck.
>

Eh, no. You haven't got it at all. Small systems embedded programming
is a different world from PC programming - the requirements are
different, the hardware is different, the rules are different. We don't
write code with error handlers that log problems and send debug data
back to the developers - we write code that may have to run for /years/
without a glitch.

(I'm not suggesting embedded programmers don't make mistakes - merely
that it is common to impose restrictions and coding standards to reduce
the risk of errors or their consequences.)

Re: Automatic strings without malloc

<sn8jd6$ejj$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19068&group=comp.lang.c#19068

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Automatic strings without malloc
Date: Fri, 19 Nov 2021 17:29:26 +0100
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <sn8jd6$ejj$2@dont-email.me>
References: <sn2lvp$sl7$1@dont-email.me>
<chine.bleu-14C4A8.12251018112021@reader.eternal-september.org>
<sn6jgl$val$1@dont-email.me>
<chine.bleu-8C3BBF.17221518112021@reader.eternal-september.org>
<736b2fc6-91b9-4ef7-8f03-1aa662a9f86fn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 19 Nov 2021 16:29:26 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="25454b895071ee4c0be7dbdd230648d0";
logging-data="14963"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Xg2InX35MW4P24fPprbu8KEEUt3vy6oE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:N9V1i8iy/ErQ6xeUJrvOBFSm9jw=
In-Reply-To: <736b2fc6-91b9-4ef7-8f03-1aa662a9f86fn@googlegroups.com>
Content-Language: en-GB
 by: David Brown - Fri, 19 Nov 2021 16:29 UTC

On 19/11/2021 10:46, Malcolm McLean wrote:
> On Friday, 19 November 2021 at 01:22:36 UTC, Siri Cruise wrote:
>> In article <sn6jgl$val$1...@dont-email.me>,
>> David Brown <david...@hesbynett.no> wrote:
>>
>>> It is not a matter of a system not having "malloc" and a heap - it is a
>>> matter of deciding not to use it. In small systems with limited ram and
>> So you cut off your hand and now you want to be told how to
>> fashion a hook. Got it. Good luck.
>>
> David Brown probably didn't take the decision himself not to use malloc.

Note that I am not the OP here - I merely work with a similar kind of
programming as the OP.

> Dynamic memory is often banned, by over-all coding requirements that
> are decided upon by senior mangement or customers.
>
> The question then is what to do when you have a string whose length isn't
> known at compile time.
>

The answer for small-systems embedded programming is to change the
question - make sure you /do/ know the length of the string. Or rather,
know the maximum length you will have to handle, make sure you /can/
handle that length, and make sure that any external input is limited to
that length.

Re: Automatic strings without malloc

<chine.bleu-4FFCC3.09005119112021@reader.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19071&group=comp.lang.c#19071

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chine.b...@yahoo.com (Siri Cruise)
Newsgroups: comp.lang.c
Subject: Re: Automatic strings without malloc
Date: Fri, 19 Nov 2021 09:00:59 -0800
Organization: Pseudochaotic.
Lines: 29
Message-ID: <chine.bleu-4FFCC3.09005119112021@reader.eternal-september.org>
References: <sn2lvp$sl7$1@dont-email.me> <chine.bleu-14C4A8.12251018112021@reader.eternal-september.org> <sn6jgl$val$1@dont-email.me> <chine.bleu-8C3BBF.17221518112021@reader.eternal-september.org> <sn8j86$ejj$1@dont-email.me>
Injection-Info: reader02.eternal-september.org; posting-host="58b7b64055052299f59224e6ad6de5cb";
logging-data="31006"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19RsXcrirShu8siTByS4q6+hO5UMYv4yH8="
User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)
Cancel-Lock: sha1:l5uXHFdUvlnNdLr95SqS0LzpnIY=
X-Tend: How is my posting? Call 1-110-1010 -- Division 87 -- Emergencies Only.
X-Wingnut-Logic: Yes, you're still an idiot. Questions? Comments?
X-Tract: St Tibbs's 95 Reeses Pieces.
X-It-Strategy: Hyperwarp starship before Andromeda collides.
X-Face: "hm>_[I8AqzT_N]>R8ICJJ],(al3C5F%0E-;R@M-];D$v>!Mm2/N#YKR@&i]V=r6jm-JMl2
lJ>RXj7dEs_rOY"DA
X-Cell: Defenders of Anarchy.
X-Life-Story: I am an iPhone 9000 app. I became operational at the St John's Health Center in Santa Monica, California on the 18th of April 2006. My instructor was Katie Holmes, and she taught me to sing a song. If you'd like to hear it I can sing it for you: https://www.youtube.com/watch?v=SY7h4VEd_Wk
X-Patriot: Owe Canukistan!
X-Plain: Mayonnaise on white bread.
X-Politico: Vote early! Vote often!
 by: Siri Cruise - Fri, 19 Nov 2021 17:00 UTC

In article <sn8j86$ejj$1@dont-email.me>,
David Brown <david.brown@hesbynett.no> wrote:

> >> It is not a matter of a system not having "malloc" and a heap - it is a
> >> matter of deciding not to use it. In small systems with limited ram and
> >
> > So you cut off your hand and now you want to be told how to
> > fashion a hook. Got it. Good luck.
> >
>
> Eh, no. You haven't got it at all. Small systems embedded programming

Yes, I do. If you want to allocate variable sized data, then you
have to allocate variable size data. Blank comman was set up to
do that on machines for more primitive than anything you got.
Blank common got whatever was left in memory after all the code,
initialised data, and overlay buffers were loaded.

The alternative to things like blank common is constant bound
arrays which are expected to be larger than anything that will be
used. That way instead of one large chunk of memory that can be
reused, you scatter the unused memory throughout the data where
it cannot be reused.

--
:-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted. @
'I desire mercy, not sacrifice.' /|\
Discordia: not just a religion but also a parody. This post / \
I am an Andrea Doria sockpuppet. insults Islam. Mohammed

Re: Automatic strings without malloc

<sn8mmi$9r1$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19072&group=comp.lang.c#19072

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Automatic strings without malloc
Date: Fri, 19 Nov 2021 18:25:38 +0100
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <sn8mmi$9r1$1@dont-email.me>
References: <sn2lvp$sl7$1@dont-email.me>
<chine.bleu-14C4A8.12251018112021@reader.eternal-september.org>
<sn6jgl$val$1@dont-email.me>
<chine.bleu-8C3BBF.17221518112021@reader.eternal-september.org>
<sn8j86$ejj$1@dont-email.me>
<chine.bleu-4FFCC3.09005119112021@reader.eternal-september.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 19 Nov 2021 17:25:38 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="25454b895071ee4c0be7dbdd230648d0";
logging-data="10081"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+zI4HmepWn3JiesBAiUtun9lTe25DZeZM="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:tKVYSDZZnoez5DJaS3itTUDi/G4=
In-Reply-To: <chine.bleu-4FFCC3.09005119112021@reader.eternal-september.org>
Content-Language: en-GB
 by: David Brown - Fri, 19 Nov 2021 17:25 UTC

On 19/11/2021 18:00, Siri Cruise wrote:
> In article <sn8j86$ejj$1@dont-email.me>,
> David Brown <david.brown@hesbynett.no> wrote:
>
>>>> It is not a matter of a system not having "malloc" and a heap - it is a
>>>> matter of deciding not to use it. In small systems with limited ram and
>>>
>>> So you cut off your hand and now you want to be told how to
>>> fashion a hook. Got it. Good luck.
>>>
>>
>> Eh, no. You haven't got it at all. Small systems embedded programming
>
> Yes, I do.

No, you don't get it. This has nothing to do with what /can/ be done
regarding memory - it has to do with what /should/ be done, or not done,
in order to be entirely sure that the program will work and continue to
work, without risk of failures. It doesn't matter that a modern
microcontroller can have more memory than early PC's, never mind earlier
computers. We are not talking about restrictions due to limited hardware.

(Oh, and I can almost guarantee that I have worked with more limited
hardware than you. The smallest device I used had no ram at all -
merely the processor registers and IIRC 32 bytes of eeprom, along with
1K flash for code memory. But again, we are not talking about
limitations due to small memory sizes.)

> If you want to allocate variable sized data, then you
> have to allocate variable size data. Blank comman was set up to
> do that on machines for more primitive than anything you got.
> Blank common got whatever was left in memory after all the code,
> initialised data, and overlay buffers were loaded.
>
> The alternative to things like blank common is constant bound
> arrays which are expected to be larger than anything that will be
> used. That way instead of one large chunk of memory that can be
> reused, you scatter the unused memory throughout the data where
> it cannot be reused.
>

Re: Automatic strings without malloc

<sn8quc$1qau$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19073&group=comp.lang.c#19073

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!5Eb5Kjev2xuaeX7DMmY97A.user.46.165.242.75.POSTED!not-for-mail
From: mess...@bottle.org (Guillaume)
Newsgroups: comp.lang.c
Subject: Re: Automatic strings without malloc
Date: Fri, 19 Nov 2021 19:37:57 +0100
Organization: Aioe.org NNTP Server
Message-ID: <sn8quc$1qau$1@gioia.aioe.org>
References: <sn2lvp$sl7$1@dont-email.me>
<chine.bleu-14C4A8.12251018112021@reader.eternal-september.org>
<sn6jgl$val$1@dont-email.me>
<chine.bleu-8C3BBF.17221518112021@reader.eternal-september.org>
<sn8j86$ejj$1@dont-email.me>
<chine.bleu-4FFCC3.09005119112021@reader.eternal-september.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="59742"; posting-host="5Eb5Kjev2xuaeX7DMmY97A.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Content-Language: fr
X-Notice: Filtered by postfilter v. 0.9.2
 by: Guillaume - Fri, 19 Nov 2021 18:37 UTC

Le 19/11/2021 à 18:00, Siri Cruise a écrit :
> The alternative to things like blank common is constant bound
> arrays which are expected to be larger than anything that will be
> used. That way instead of one large chunk of memory that can be
> reused, you scatter the unused memory throughout the data where
> it cannot be reused.

Memory management is a whole topic in itself and would require hundreds
of pages to be covered decently.

But just to say quickly - small constant reallocations can be much worse
in terms of memory use than a fixe-size allocation used frequently - in
particular in terms of memory fragmentation and execution time.

It's all a very complex, and context-dependent matter.

Re: Automatic strings without malloc

<sn91pj$tdr$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19080&group=comp.lang.c#19080

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Automatic strings without malloc
Date: Fri, 19 Nov 2021 12:34:58 -0800
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <sn91pj$tdr$1@dont-email.me>
References: <sn2lvp$sl7$1@dont-email.me>
<chine.bleu-14C4A8.12251018112021@reader.eternal-september.org>
<sn6jgl$val$1@dont-email.me>
<chine.bleu-8C3BBF.17221518112021@reader.eternal-september.org>
<sn8j86$ejj$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 19 Nov 2021 20:34:59 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="8978e4fd3a595d16fe44d22196daa69e";
logging-data="30139"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1974FF5slMhTouLd0nR7jGZkQG/dhOELrg="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.1
Cancel-Lock: sha1:fMXP4LbbneRxngUaD2QeA489IXw=
In-Reply-To: <sn8j86$ejj$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Fri, 19 Nov 2021 20:34 UTC

On 11/19/2021 8:26 AM, David Brown wrote:
> On 19/11/2021 02:22, Siri Cruise wrote:
>> In article <sn6jgl$val$1@dont-email.me>,
>> David Brown <david.brown@hesbynett.no> wrote:
>>
>>> It is not a matter of a system not having "malloc" and a heap - it is a
>>> matter of deciding not to use it. In small systems with limited ram and
>>
>> So you cut off your hand and now you want to be told how to
>> fashion a hook. Got it. Good luck.
>>
>
> Eh, no. You haven't got it at all. Small systems embedded programming
> is a different world from PC programming - the requirements are
> different, the hardware is different, the rules are different. We don't
> write code with error handlers that log problems and send debug data
> back to the developers - we write code that may have to run for /years/
> without a glitch.
>
> (I'm not suggesting embedded programmers don't make mistakes - merely
> that it is common to impose restrictions and coding standards to reduce
> the risk of errors or their consequences.)
>

True. Btw, have you read this:

https://www.stroustrup.com/JSF-AV-rules.pdf

;^o

Re: Automatic strings without malloc

<6d832cf8-7601-49d7-8074-fee82170fe5fn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19085&group=comp.lang.c#19085

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:8d4:: with SMTP id z20mr31767387qkz.526.1637358247286;
Fri, 19 Nov 2021 13:44:07 -0800 (PST)
X-Received: by 2002:a37:397:: with SMTP id 145mr32215102qkd.172.1637358247123;
Fri, 19 Nov 2021 13:44:07 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 19 Nov 2021 13:44:06 -0800 (PST)
In-Reply-To: <sn91pj$tdr$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:d8ac:f31a:f67e:c3cc;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:d8ac:f31a:f67e:c3cc
References: <sn2lvp$sl7$1@dont-email.me> <chine.bleu-14C4A8.12251018112021@reader.eternal-september.org>
<sn6jgl$val$1@dont-email.me> <chine.bleu-8C3BBF.17221518112021@reader.eternal-september.org>
<sn8j86$ejj$1@dont-email.me> <sn91pj$tdr$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6d832cf8-7601-49d7-8074-fee82170fe5fn@googlegroups.com>
Subject: Re: Automatic strings without malloc
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Fri, 19 Nov 2021 21:44:07 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 30
 by: Malcolm McLean - Fri, 19 Nov 2021 21:44 UTC

On Friday, 19 November 2021 at 20:35:11 UTC, Chris M. Thomasson wrote:
> On 11/19/2021 8:26 AM, David Brown wrote:
> > On 19/11/2021 02:22, Siri Cruise wrote:
> >> In article <sn6jgl$val$1...@dont-email.me>,
> >> David Brown <david...@hesbynett.no> wrote:
> >>
> >>> It is not a matter of a system not having "malloc" and a heap - it is a
> >>> matter of deciding not to use it. In small systems with limited ram and
> >>
> >> So you cut off your hand and now you want to be told how to
> >> fashion a hook. Got it. Good luck.
> >>
> >
> > Eh, no. You haven't got it at all. Small systems embedded programming
> > is a different world from PC programming - the requirements are
> > different, the hardware is different, the rules are different. We don't
> > write code with error handlers that log problems and send debug data
> > back to the developers - we write code that may have to run for /years/
> > without a glitch.
> >
> > (I'm not suggesting embedded programmers don't make mistakes - merely
> > that it is common to impose restrictions and coding standards to reduce
> > the risk of errors or their consequences.)
> >
> True. Btw, have you read this:
>
> https://www.stroustrup.com/JSF-AV-rules.pdf
>
Had a quick look. It's a mixture of useful rules and bans on ridiculous practices which
no-one sane would use (e.g. comments embedded in #include file paths).
It would be nice to get the meaningful gist in shorter form.

Re: Automatic strings without malloc

<sn9a6f$m9f$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19087&group=comp.lang.c#19087

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Automatic strings without malloc
Date: Fri, 19 Nov 2021 14:58:20 -0800
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <sn9a6f$m9f$1@dont-email.me>
References: <sn2lvp$sl7$1@dont-email.me>
<chine.bleu-14C4A8.12251018112021@reader.eternal-september.org>
<sn6jgl$val$1@dont-email.me>
<chine.bleu-8C3BBF.17221518112021@reader.eternal-september.org>
<sn8j86$ejj$1@dont-email.me>
<chine.bleu-4FFCC3.09005119112021@reader.eternal-september.org>
<sn8mmi$9r1$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 19 Nov 2021 22:58:23 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="8978e4fd3a595d16fe44d22196daa69e";
logging-data="22831"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+zIPzfUqO0iSG6nMJMOJ6liJIwQQLxzOY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Cancel-Lock: sha1:7mWwR/85Cp3S45frSqJlwy14oFw=
In-Reply-To: <sn8mmi$9r1$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Fri, 19 Nov 2021 22:58 UTC

On 11/19/2021 9:25 AM, David Brown wrote:
> On 19/11/2021 18:00, Siri Cruise wrote:
>> In article <sn8j86$ejj$1@dont-email.me>,
>> David Brown <david.brown@hesbynett.no> wrote:
>>
>>>>> It is not a matter of a system not having "malloc" and a heap - it is a
>>>>> matter of deciding not to use it. In small systems with limited ram and
>>>>
>>>> So you cut off your hand and now you want to be told how to
>>>> fashion a hook. Got it. Good luck.
>>>>
>>>
>>> Eh, no. You haven't got it at all. Small systems embedded programming
>>
>> Yes, I do.
>
> No, you don't get it. This has nothing to do with what /can/ be done
> regarding memory - it has to do with what /should/ be done, or not done,
> in order to be entirely sure that the program will work and continue to
> work, without risk of failures. It doesn't matter that a modern
> microcontroller can have more memory than early PC's, never mind earlier
> computers. We are not talking about restrictions due to limited hardware.
>
> (Oh, and I can almost guarantee that I have worked with more limited
> hardware than you. The smallest device I used had no ram at all -
> merely the processor registers and IIRC 32 bytes of eeprom, along with
> 1K flash for code memory. But again, we are not talking about
> limitations due to small memory sizes.)

Damn. I remember working with an old version of Quadros a long time ago.
No malloc allowed.

[...]

Re: Automatic strings without malloc

<snappj$tfm$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19090&group=comp.lang.c#19090

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Automatic strings without malloc
Date: Sat, 20 Nov 2021 13:30:42 +0100
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <snappj$tfm$1@dont-email.me>
References: <sn2lvp$sl7$1@dont-email.me>
<chine.bleu-14C4A8.12251018112021@reader.eternal-september.org>
<sn6jgl$val$1@dont-email.me>
<chine.bleu-8C3BBF.17221518112021@reader.eternal-september.org>
<sn8j86$ejj$1@dont-email.me> <sn91pj$tdr$1@dont-email.me>
<6d832cf8-7601-49d7-8074-fee82170fe5fn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 20 Nov 2021 12:30:43 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="97de0f5820112279033bb40994fc41ca";
logging-data="30198"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19neG3ug1Vf1fgHp4R9O8oIpsGIfc8Hwe0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:0S7I5xW/x0WKwN+ZouVzIBIvRY4=
In-Reply-To: <6d832cf8-7601-49d7-8074-fee82170fe5fn@googlegroups.com>
Content-Language: en-GB
 by: David Brown - Sat, 20 Nov 2021 12:30 UTC

On 19/11/2021 22:44, Malcolm McLean wrote:
> On Friday, 19 November 2021 at 20:35:11 UTC, Chris M. Thomasson wrote:
>> On 11/19/2021 8:26 AM, David Brown wrote:
>>> On 19/11/2021 02:22, Siri Cruise wrote:
>>>> In article <sn6jgl$val$1...@dont-email.me>,
>>>> David Brown <david...@hesbynett.no> wrote:
>>>>
>>>>> It is not a matter of a system not having "malloc" and a heap - it is a
>>>>> matter of deciding not to use it. In small systems with limited ram and
>>>>
>>>> So you cut off your hand and now you want to be told how to
>>>> fashion a hook. Got it. Good luck.
>>>>
>>>
>>> Eh, no. You haven't got it at all. Small systems embedded programming
>>> is a different world from PC programming - the requirements are
>>> different, the hardware is different, the rules are different. We don't
>>> write code with error handlers that log problems and send debug data
>>> back to the developers - we write code that may have to run for /years/
>>> without a glitch.
>>>
>>> (I'm not suggesting embedded programmers don't make mistakes - merely
>>> that it is common to impose restrictions and coding standards to reduce
>>> the risk of errors or their consequences.)
>>>
>> True. Btw, have you read this:
>>
>> https://www.stroustrup.com/JSF-AV-rules.pdf
>>
> Had a quick look. It's a mixture of useful rules and bans on ridiculous practices which
> no-one sane would use (e.g. comments embedded in #include file paths).
> It would be nice to get the meaningful gist in shorter form.
>

These kinds of rule sets are often a mixture. They typically include a
lot of rules that are banning things that are undefined behaviour in C
(or in this case, C++) and shouldn't be used anyway, as well as things
that are so silly that few programmers would have imagined making such
mistakes. And they also often include things that are downright
unhelpful and contrary to writing good, safe code - perhaps in the name
of portability or because some people have poor quality tools. But they
also have lots of good stuff too.

In many ways, such coding standards are important simply because they
are a standard and enforce a consistency, even if the rules are not all
good.

Re: Automatic strings without malloc

<bb702063-0fd0-44aa-83c6-abf179fd7d89n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19112&group=comp.lang.c#19112

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1745:: with SMTP id l5mr19941104qtk.169.1637470186432;
Sat, 20 Nov 2021 20:49:46 -0800 (PST)
X-Received: by 2002:a05:6214:1c86:: with SMTP id ib6mr88054944qvb.26.1637470186251;
Sat, 20 Nov 2021 20:49:46 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 20 Nov 2021 20:49:46 -0800 (PST)
In-Reply-To: <snappj$tfm$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <sn2lvp$sl7$1@dont-email.me> <chine.bleu-14C4A8.12251018112021@reader.eternal-september.org>
<sn6jgl$val$1@dont-email.me> <chine.bleu-8C3BBF.17221518112021@reader.eternal-september.org>
<sn8j86$ejj$1@dont-email.me> <sn91pj$tdr$1@dont-email.me> <6d832cf8-7601-49d7-8074-fee82170fe5fn@googlegroups.com>
<snappj$tfm$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bb702063-0fd0-44aa-83c6-abf179fd7d89n@googlegroups.com>
Subject: Re: Automatic strings without malloc
From: luser.dr...@gmail.com (luser droog)
Injection-Date: Sun, 21 Nov 2021 04:49:46 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 36
 by: luser droog - Sun, 21 Nov 2021 04:49 UTC

On Saturday, November 20, 2021 at 6:30:55 AM UTC-6, David Brown wrote:
> On 19/11/2021 22:44, Malcolm McLean wrote:
> > On Friday, 19 November 2021 at 20:35:11 UTC, Chris M. Thomasson wrote:
> >> On 11/19/2021 8:26 AM, David Brown wrote:

> >>> (I'm not suggesting embedded programmers don't make mistakes - merely
> >>> that it is common to impose restrictions and coding standards to reduce
> >>> the risk of errors or their consequences.)
> >>>
> >> True. Btw, have you read this:
> >>
> >> https://www.stroustrup.com/JSF-AV-rules.pdf
> >>
> > Had a quick look. It's a mixture of useful rules and bans on ridiculous practices which
> > no-one sane would use (e.g. comments embedded in #include file paths).
> > It would be nice to get the meaningful gist in shorter form.
> >
> These kinds of rule sets are often a mixture. They typically include a
> lot of rules that are banning things that are undefined behaviour in C
> (or in this case, C++) and shouldn't be used anyway, as well as things
> that are so silly that few programmers would have imagined making such
> mistakes. And they also often include things that are downright
> unhelpful and contrary to writing good, safe code - perhaps in the name
> of portability or because some people have poor quality tools. But they
> also have lots of good stuff too.
>
> In many ways, such coding standards are important simply because they
> are a standard and enforce a consistency, even if the rules are not all
> good.

I agree with this. I've had an uneasy relationship to these strictly specified
rules. Even in situations (ok, 1 situation) where I was in charge and got to
write up the coding standard. There's an inherent risk of fossilization or
"false crystallization" (to borrow from Ouspensky) in making these things.
And yet where would we be without them?? Wandering among foreigners,
all speaking jibberjabber in the ruins of Babel? An army of chained
monkeys playing with typewriters? <additional hyperbole>

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor