Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

God made the integers; all else is the work of Man. -- Kronecker


devel / comp.lang.c / Re: Why does C allow structs to have a tag?

SubjectAuthor
* Why does C allow structs to have a tag?James Harris
+* Re: Why does C allow structs to have a tag?David Brown
|`* Re: Why does C allow structs to have a tag?Thiago Adams
| `- Re: Why does C allow structs to have a tag?David Brown
+- Re: Why does C allow structs to have a tag?Öö Tiib
+* Re: Why does C allow structs to have a tag?Bart
|+* Re: Why does C allow structs to have a tag?Kaz Kylheku
||+- Re: Why does C allow structs to have a tag?Bart
||`* Re: Why does C allow structs to have a tag?Manfred
|| `* Re: Why does C allow structs to have a tag?David Brown
||  `* Re: Why does C allow structs to have a tag?Bart
||   +- Re: Why does C allow structs to have a tag?Richard Harnden
||   +* Re: Why does C allow structs to have a tag?Keith Thompson
||   |+* Re: Why does C allow structs to have a tag?Bart
||   ||+- Re: Why does C allow structs to have a tag?Keith Thompson
||   ||`* Re: Why does C allow structs to have a tag?James Harris
||   || `- Re: Why does C allow structs to have a tag?Bart
||   |`* Re: Why does C allow structs to have a tag?Manfred
||   | `* Re: Why does C allow structs to have a tag?Keith Thompson
||   |  `* Re: Why does C allow structs to have a tag?Bart
||   |   +* Re: Why does C allow structs to have a tag?David Brown
||   |   |`- Re: Why does C allow structs to have a tag?Bart
||   |   `* Re: Why does C allow structs to have a tag?Keith Thompson
||   |    `- Re: Why does C allow structs to have a tag?Malcolm McLean
||   `* Re: Why does C allow structs to have a tag?David Brown
||    `* Re: Why does C allow structs to have a tag?Bart
||     +* Re: Why does C allow structs to have a tag?David Brown
||     |`* Re: Why does C allow structs to have a tag?Bart
||     | `* Re: Why does C allow structs to have a tag?Malcolm McLean
||     |  `* Re: Why does C allow structs to have a tag?Bart
||     |   `* Re: Why does C allow structs to have a tag?Kaz Kylheku
||     |    `* Re: Why does C allow structs to have a tag?Bart
||     |     +- Re: Why does C allow structs to have a tag?James Harris
||     |     `* Re: Why does C allow structs to have a tag?Kaz Kylheku
||     |      `* Re: Why does C allow structs to have a tag?Bart
||     |       `* Re: Why does C allow structs to have a tag?Keith Thompson
||     |        `* Re: Why does C allow structs to have a tag?Bart
||     |         `- Re: Why does C allow structs to have a tag?Keith Thompson
||     `* Re: Why does C allow structs to have a tag?James Harris
||      `- Re: Why does C allow structs to have a tag?Bart
|`- Re: Why does C allow structs to have a tag?Keith Thompson
+* Re: Why does C allow structs to have a tag?Kaz Kylheku
|`* Re: Why does C allow structs to have a tag?Bart
| `- Re: Why does C allow structs to have a tag?James Harris
+- Re: Why does C allow structs to have a tag?James Kuyper
+* Re: Why does C allow structs to have a tag?Richard Damon
|`- Re: Why does C allow structs to have a tag?James Harris
+* Re: Why does C allow structs to have a tag?Joe Pfeiffer
|`* Re: Why does C allow structs to have a tag?Malcolm McLean
| +* Re: Why does C allow structs to have a tag?Guillaume
| |+* Re: Why does C allow structs to have a tag?Kaz Kylheku
| ||`* Re: Why does C allow structs to have a tag?Bart
| || `* Re: Why does C allow structs to have a tag?Kaz Kylheku
| ||  `* Re: Why does C allow structs to have a tag?Bart
| ||   `- Re: Why does C allow structs to have a tag?Keith Thompson
| |`* Re: Why does C allow structs to have a tag?James Kuyper
| | `* Re: Why does C allow structs to have a tag?Bart
| |  `* Re: Why does C allow structs to have a tag?Kaz Kylheku
| |   +* Re: Why does C allow structs to have a tag?Bart
| |   |`* Re: Why does C allow structs to have a tag?Kaz Kylheku
| |   | `* Re: Why does C allow structs to have a tag?Bart
| |   |  `* Re: Why does C allow structs to have a tag?David Brown
| |   |   `* Re: Why does C allow structs to have a tag?Bart
| |   |    +* Re: Why does C allow structs to have a tag?David Brown
| |   |    |`* Re: Why does C allow structs to have a tag?Bart
| |   |    | `* Re: Why does C allow structs to have a tag?David Brown
| |   |    |  +* Re: Why does C allow structs to have a tag?Manfred
| |   |    |  |`- Re: Why does C allow structs to have a tag?David Brown
| |   |    |  +- Re: Why does C allow structs to have a tag?Bart
| |   |    |  `* Re: Why does C allow structs to have a tag?Bart
| |   |    |   +- Re: Why does C allow structs to have a tag?David Brown
| |   |    |   `* Re: Why does C allow structs to have a tag?Keith Thompson
| |   |    |    +* Re: Why does C allow structs to have a tag?Guillaume
| |   |    |    |+* Re: Why does C allow structs to have a tag?Kaz Kylheku
| |   |    |    ||`- Re: Why does C allow structs to have a tag?Keith Thompson
| |   |    |    |+- Re: Why does C allow structs to have a tag?Keith Thompson
| |   |    |    |+- Re: Why does C allow structs to have a tag?Keith Thompson
| |   |    |    |`- Re: Why does C allow structs to have a tag?David Brown
| |   |    |    `* Re: Why does C allow structs to have a tag?Bart
| |   |    |     `* Re: Why does C allow structs to have a tag?Keith Thompson
| |   |    |      `* Re: Why does C allow structs to have a tag?Bart
| |   |    |       +* Re: Why does C allow structs to have a tag?Kaz Kylheku
| |   |    |       |`* Re: Why does C allow structs to have a tag?Ben Bacarisse
| |   |    |       | `* Re: Why does C allow structs to have a tag?Bart
| |   |    |       |  `* Re: Why does C allow structs to have a tag?Kaz Kylheku
| |   |    |       |   `* Re: Why does C allow structs to have a tag?Bart
| |   |    |       |    +* Re: Why does C allow structs to have a tag?Kaz Kylheku
| |   |    |       |    |`* Re: Why does C allow structs to have a tag?Bart
| |   |    |       |    | `- Re: Why does C allow structs to have a tag?Keith Thompson
| |   |    |       |    `- Re: Why does C allow structs to have a tag?Keith Thompson
| |   |    |       `- Re: Why does C allow structs to have a tag?David Brown
| |   |    `* Re: Why does C allow structs to have a tag?Kaz Kylheku
| |   |     `* Re: Why does C allow structs to have a tag?Bart
| |   |      `* Re: Why does C allow structs to have a tag?Kaz Kylheku
| |   |       `- Re: Why does C allow structs to have a tag?Bart
| |   `* Re: Why does C allow structs to have a tag?Bart
| |    +- Re: Why does C allow structs to have a tag?Keith Thompson
| |    `- Re: Why does C allow structs to have a tag?Kaz Kylheku
| +* Re: Why does C allow structs to have a tag?Joe Pfeiffer
| |`- Re: Why does C allow structs to have a tag?Kaz Kylheku
| `- Re: Why does C allow structs to have a tag?Richard Damon
+* Re: Why does C allow structs to have a tag?John Bode
+- Re: Why does C allow structs to have a tag?Siri Cruise
`* Re: Why does C allow structs to have a tag?Andrey Tarasevich

Pages:12345678910111213141516
Re: Why does C allow structs to have a tag?

<2c0cb99f-2d5f-4149-8b03-d96ecc3d6543n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:88c:: with SMTP id b12mr16160715qka.483.1628679302214;
Wed, 11 Aug 2021 03:55:02 -0700 (PDT)
X-Received: by 2002:ae9:f504:: with SMTP id o4mr33971866qkg.17.1628679302088;
Wed, 11 Aug 2021 03:55:02 -0700 (PDT)
Path: i2pn2.org!i2pn.org!news.niel.me!usenet.pasdenom.info!usenet-fr.net!fdn.fr!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: Wed, 11 Aug 2021 03:55:01 -0700 (PDT)
In-Reply-To: <sf021q$78n$1@z-news.wcss.wroc.pl>
Injection-Info: google-groups.googlegroups.com; posting-host=199.203.251.52; posting-account=ow8VOgoAAAAfiGNvoH__Y4ADRwQF1hZW
NNTP-Posting-Host: 199.203.251.52
References: <s9iea5$n5c$1@dont-email.me> <see71a$gk4$1@dont-email.me>
<seebtt$jrq$1@dont-email.me> <CjzOI.1030$Bg6.61@fx42.iad> <seejf8$9ti$1@dont-email.me>
<WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me>
<CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me> <87czqnlp2m.fsf@bsb.me.uk>
<WFWPI.1865$un2.1665@fx04.iad> <FiCQI.401$uk4.259@fx20.iad>
<poCQI.37363$EF2.25668@fx47.iad> <VNCQI.5685$Ug5.514@fx24.iad>
<seuu75$il3$1@dont-email.me> <TEEQI.5686$Ug5.143@fx24.iad> <sf021q$78n$1@z-news.wcss.wroc.pl>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2c0cb99f-2d5f-4149-8b03-d96ecc3d6543n@googlegroups.com>
Subject: Re: Why does C allow structs to have a tag?
From: already5...@yahoo.com (Michael S)
Injection-Date: Wed, 11 Aug 2021 10:55:02 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Michael S - Wed, 11 Aug 2021 10:55 UTC

On Wednesday, August 11, 2021 at 11:34:16 AM UTC+3, anti...@math.uni.wroc.pl wrote:
> DFS <nos...@dfs.com> wrote:
> >
> > Thanks. I created a static array[10_000_000] outside the function, and
> > it handled large results sets just fine. But another issue popped up,
> > using option 2, which concatenates words one by one into that static
> > array, then does one puts() at the end.
> >
> > Turns out it's VERY slow for large result sets.
> >
> > Option 1 Option 2
> > substring catt: 91 matches found 0.04s 0.038s
> > substring cat : 3710 matches found 0.20s 0.16s
> > substring ca : 22793 matches found 1.39s 2.25s
> > substring c : 128689 matches found 7.75s 57.91s
> > substring e : 252896 matches found 15.29s 216.58s
> >
> > Option 1 starts printing immediately, one line at a time. Option 2 sits
> > there constructing that long string for quite a while. Too long I
> > think. What might I be doing wrong?
> >
> > Note: the timing includes time to print to screen. Just finding the
> > word matches is 0.03s using either option.
> >
> >
> > =================================================================
> >
> > //option 1: one puts per line (suggested by bart)
> > int i = 0;
> > char buff[longword+3];
> > char line[tcols];
> > *line = '\0';
> > while(i < matchcnt) {
> > for(int j = 1;j<=maxcols;j++) {
> > sprintf(buff,"%-*s ",longword,matchwords[i++]);
> > strcat(line,buff);
> > }
> > puts(line);
> > *buff = '\0';
> > *line = '\0';
> > }
> >
> > =================================================================
> >
> > //option 2: one big string, one puts (per Lurndal)
> > static char line[10000000]; //declared outside the func
> >
> > int i = 0;
> > char buff[longword+3];
> > *line = '\0';
> > while(i < matchcnt) {
> > for(int j = 1;j<=maxcols;j++) {
> > sprintf(buff,"%-*s ",longword,matchwords[i++]);
> > strcat(line,buff);
> ^^^^^^^^^^^^^^^^^^
> > }
> > *buff = '\0';
> > strcat(line,"\n");
> > }
> > puts(line);
> >
> > =================================================================
> The 'strcat' in a loop is classic antipattern: it causes quadratic
> complexity to to repeated scanning for end of 'line'. Use something
> like
>
> char * cp = line;
> .....
> strcat(cp, buff);
> cp += strlen(buff);
> ....
>
>
> --
> Waldek Hebisch

strcat() should have been deprecated in 1989 with replacement that returns something potentially useful, e.g. pointer to
termination character of result string or length of result string. Or return nothing, which still would be an improvement.

But committees have their own logic.

Re: Why does C allow structs to have a tag?

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

  copy mid

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

  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: Why does C allow structs to have a tag?
Date: Wed, 11 Aug 2021 14:29:38 +0100
Organization: A noiseless patient Spider
Lines: 81
Message-ID: <87tujwgldp.fsf@bsb.me.uk>
References: <s9iea5$n5c$1@dont-email.me> <see71a$gk4$1@dont-email.me>
<seebtt$jrq$1@dont-email.me> <CjzOI.1030$Bg6.61@fx42.iad>
<seejf8$9ti$1@dont-email.me> <WowPI.4743$NQ1.1007@fx48.iad>
<sembba$oul$1@dont-email.me> <CrQPI.669$bS5.239@fx21.iad>
<seoqf4$pj7$1@dont-email.me> <87czqnlp2m.fsf@bsb.me.uk>
<WFWPI.1865$un2.1665@fx04.iad> <FiCQI.401$uk4.259@fx20.iad>
<poCQI.37363$EF2.25668@fx47.iad> <VNCQI.5685$Ug5.514@fx24.iad>
<seuu75$il3$1@dont-email.me> <TEEQI.5686$Ug5.143@fx24.iad>
<sf021q$78n$1@z-news.wcss.wroc.pl> <875ywci8k0.fsf@bsb.me.uk>
<63773d19-8176-43a0-9c6d-47f72b1e1c10n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="5cec1deac9f4bcbbf715d1b469393f55";
logging-data="1017"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ikftPLGbnx9/V7GIHy5SDRpWPE8SfgVQ="
Cancel-Lock: sha1:CsjN0Ydo9+HytHuiGcDE+VcSlKU=
sha1:mMXjPEeICO8ez0X+KYxY0ZzImcg=
X-BSB-Auth: 1.32382bdc8e266830b614.20210811142938BST.87tujwgldp.fsf@bsb.me.uk
 by: Ben Bacarisse - Wed, 11 Aug 2021 13:29 UTC

Michael S <already5chosen@yahoo.com> writes:

> On Wednesday, August 11, 2021 at 1:23:55 PM UTC+3, Ben Bacarisse wrote:
>> anti...@math.uni.wroc.pl writes:
>>
>> > DFS <nos...@dfs.com> wrote:
>> <cut>
>> >> =================================================================
>> >>
>> >> //option 1: one puts per line (suggested by bart)
>> >> int i = 0;
>> >> char buff[longword+3];
>> >> char line[tcols];
>> >> *line = '\0';
>> >> while(i < matchcnt) {
>> >> for(int j = 1;j<=maxcols;j++) {
>> >> sprintf(buff,"%-*s ",longword,matchwords[i++]);
>> >> strcat(line,buff);
>> >> }
>> >> puts(line);
>> >> *buff = '\0';
>> >> *line = '\0';
>> >> }
>> >>
>> >> =================================================================
>> >>
>> >> //option 2: one big string, one puts (per Lurndal)
>> >> static char line[10000000]; //declared outside the func
>> >>
>> >> int i = 0;
>> >> char buff[longword+3];
>> >> *line = '\0';
>> >> while(i < matchcnt) {
>> >> for(int j = 1;j<=maxcols;j++) {
>> >> sprintf(buff,"%-*s ",longword,matchwords[i++]);
>> >> strcat(line,buff);
>> > ^^^^^^^^^^^^^^^^^^
>> >> }
>> >> *buff = '\0';
>> >> strcat(line,"\n");
>> >> }
>> >> puts(line);
>> >>
>> >> =================================================================
>> >
>> > The 'strcat' in a loop is classic antipattern: it causes quadratic
>> > complexity to to repeated scanning for end of 'line'. Use something
>> > like
>> >
>> > char * cp = line;
>> > .....
>> > strcat(cp, buff);
>> > cp += strlen(buff);
>> > ....
>> ... or get the length first and use memcpy. But my favourite is
>>
>> cp += snprintf(cp, "%s", whatever);
>>
>> --
>> Ben.
>
> Don't you mean sprintf() ?

Yes, thanks. Finger memory making me type letters.

> snprintf() requires one more parameter (size of the target buffer) and
> does *not* return the number of actually written characters when
> buffer is too small.

snprintf is, in fact, what one usually wants to avoid making assumptions
about available space (hence my urge to type it!) but the pattern
becomes more complex in portable code because you can't write this:

while (cp < ep) cp += snprintf(cp, ep - cp, "%s", whatever);

because the construction of the pointer (and the subsequent comparison)
are undefined. Once the pattern gets more complicated, other options
start to look simpler.

--
Ben.

Re: Why does C allow structs to have a tag?

<GCQQI.17254$lK.16624@fx41.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!feeder.usenetexpress.com!tr2.eu1.usenetexpress.com!feeder1.feed.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx41.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Why does C allow structs to have a tag?
Newsgroups: comp.lang.c
References: <s9iea5$n5c$1@dont-email.me> <see71a$gk4$1@dont-email.me> <seebtt$jrq$1@dont-email.me> <CjzOI.1030$Bg6.61@fx42.iad> <seejf8$9ti$1@dont-email.me> <WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me> <CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me> <87czqnlp2m.fsf@bsb.me.uk> <WFWPI.1865$un2.1665@fx04.iad> <FiCQI.401$uk4.259@fx20.iad> <poCQI.37363$EF2.25668@fx47.iad> <VNCQI.5685$Ug5.514@fx24.iad> <seuu75$il3$1@dont-email.me> <TEEQI.5686$Ug5.143@fx24.iad>
Lines: 70
Message-ID: <GCQQI.17254$lK.16624@fx41.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 11 Aug 2021 13:52:38 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 11 Aug 2021 13:52:38 GMT
X-Received-Bytes: 3493
 by: Scott Lurndal - Wed, 11 Aug 2021 13:52 UTC

DFS <nospam@dfs.com> writes:
>On 8/10/2021 6:22 PM, Bart wrote:
>> On 10/08/2021 23:08, DFS wrote:
>>> On 8/10/2021 2:41 PM, Scott Lurndal wrote:
>>
>>>> I was suggesting that the compiler could have just
>>>> stored a 160k string in RO storage and called puts
>>>> with a pointer to it.   There is no need to construct
>>>> it at runtime.
>>>>
>>>> The entire program would reduce to a single call
>>>> to puts with a compiler generated constant string.
>>>
>>> Gotcha.
>>>
>>> I just noticed something in my program.  Using option 2 above, the
>>> version compiled by tcc crashes when the value in line 3 is large
>>> (1027424).  The version compiled by gcc doesn't crash.
>>>
>>> Is that a stack overflow issue?
>>>
>>
>> Yes, you're using VLAs, (maybe in option 1 too if longword and tcols are
>> not compile-time constants).
>
>They're not. Longword is the longest word (1 to 31) in a result set,
>and tcols is the width of your terminal at the time you do the search.
>
>Here's the app: https://imgur.com/a/cQdvAeM
>
>
>
>> Typical stack size is a few MB. It seems the default stack size of tcc
>> is smaller than of gcc**. tcc crashes with this:
>>
>>     int n=2000000;
>>     char str[n];
>>     memset(str,0,n);
>>
>> but gcc doesn't, until you change n to 4000000. If I dump the two
>> executables, then the gcc one contains this:
>>
>>   Stack reserve:    2097152
>>   Stack commit:     4096
>>
>> tcc's has:
>>
>>   Stack reserve:    1048576
>>   Stack commit:     4096
>>
>> There are probably ways of increasing the stack size, but better not to
>> use VLAs for arrays of this size. (Use static arrays or allocate on the
>> heap.)
>
>
>Thanks. I created a static array[10_000_000] outside the function, and
>it handled large results sets just fine. But another issue popped up,
>using option 2, which concatenates words one by one into that static
>array, then does one puts() at the end.
>
>Turns out it's VERY slow for large result sets.

strcat is almost never the right interface to use. It needs
to scan the entire string to find the terminal nul-byte before
appending. As the string gets longer, each strcat takes longer
than the one before.

Just keep a pointer to the next element and increment the
pointer each time you add a new element.

Re: Why does C allow structs to have a tag?

<kFQQI.17255$lK.6119@fx41.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx41.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Why does C allow structs to have a tag?
Newsgroups: comp.lang.c
References: <s9iea5$n5c$1@dont-email.me> <seejf8$9ti$1@dont-email.me> <WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me> <CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me> <87czqnlp2m.fsf@bsb.me.uk> <WFWPI.1865$un2.1665@fx04.iad> <FiCQI.401$uk4.259@fx20.iad> <poCQI.37363$EF2.25668@fx47.iad> <VNCQI.5685$Ug5.514@fx24.iad> <seuu75$il3$1@dont-email.me> <TEEQI.5686$Ug5.143@fx24.iad> <sf021q$78n$1@z-news.wcss.wroc.pl> <2c0cb99f-2d5f-4149-8b03-d96ecc3d6543n@googlegroups.com>
Lines: 16
Message-ID: <kFQQI.17255$lK.6119@fx41.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 11 Aug 2021 13:55:28 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 11 Aug 2021 13:55:28 GMT
X-Received-Bytes: 1823
 by: Scott Lurndal - Wed, 11 Aug 2021 13:55 UTC

Michael S <already5chosen@yahoo.com> writes:
>On Wednesday, August 11, 2021 at 11:34:16 AM UTC+3, anti...@math.uni.wroc.pl wrote:

>
>strcat() should have been deprecated in 1989 with replacement that returns something potentially useful, e.g. pointer to
>termination character of result string or length of result string. Or return nothing, which still would be an improvement.
>
>But committees have their own logic.

Having been a member of those committees for a decade,
I'll point out that deprecating or changing the semantics of strcat
would have broken vast amounts of existing, functioning
and useful code.

Secondly, as pointed out in the thread, the function snprintf
is a suitable substitute.

Re: Why does C allow structs to have a tag?

<1f79b2e5-0e07-488f-a529-c00f7d6e046fn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:aed:2163:: with SMTP id 90mr30063383qtc.186.1628690859779;
Wed, 11 Aug 2021 07:07:39 -0700 (PDT)
X-Received: by 2002:a05:620a:1341:: with SMTP id c1mr5919318qkl.348.1628690859634;
Wed, 11 Aug 2021 07:07:39 -0700 (PDT)
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: Wed, 11 Aug 2021 07:07:39 -0700 (PDT)
In-Reply-To: <kFQQI.17255$lK.6119@fx41.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=199.203.251.52; posting-account=ow8VOgoAAAAfiGNvoH__Y4ADRwQF1hZW
NNTP-Posting-Host: 199.203.251.52
References: <s9iea5$n5c$1@dont-email.me> <seejf8$9ti$1@dont-email.me>
<WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me>
<CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me> <87czqnlp2m.fsf@bsb.me.uk>
<WFWPI.1865$un2.1665@fx04.iad> <FiCQI.401$uk4.259@fx20.iad>
<poCQI.37363$EF2.25668@fx47.iad> <VNCQI.5685$Ug5.514@fx24.iad>
<seuu75$il3$1@dont-email.me> <TEEQI.5686$Ug5.143@fx24.iad>
<sf021q$78n$1@z-news.wcss.wroc.pl> <2c0cb99f-2d5f-4149-8b03-d96ecc3d6543n@googlegroups.com>
<kFQQI.17255$lK.6119@fx41.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1f79b2e5-0e07-488f-a529-c00f7d6e046fn@googlegroups.com>
Subject: Re: Why does C allow structs to have a tag?
From: already5...@yahoo.com (Michael S)
Injection-Date: Wed, 11 Aug 2021 14:07:39 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Michael S - Wed, 11 Aug 2021 14:07 UTC

On Wednesday, August 11, 2021 at 4:55:41 PM UTC+3, Scott Lurndal wrote:
> Michael S <already...@yahoo.com> writes:
> >On Wednesday, August 11, 2021 at 11:34:16 AM UTC+3, anti...@math.uni.wroc.pl wrote:
>
> >
> >strcat() should have been deprecated in 1989 with replacement that returns something potentially useful, e.g. pointer to
> >termination character of result string or length of result string. Or return nothing, which still would be an improvement.
> >
> >But committees have their own logic.
> Having been a member of those committees for a decade,
> I'll point out that deprecating or changing the semantics of strcat

For me, deprecation does not mean *immediate* removal. For me, it mean that we threaten to remove a function in 15 years time and are actually removing it after 30 years. Or never. But in the mean time conforming compilers issue annoying diagnostics.

And, of course, nobody suggest changing semantic without changing name.

> would have broken vast amounts of existing, functioning
> and useful code.
>
> Secondly, as pointed out in the thread, the function snprintf
> is a suitable substitute.

No, sprintf() is more like strcpy(). And snprintf() differs even more.

Re: Why does C allow structs to have a tag?

<abc90066-026b-489d-9792-596e584c0af1n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:552:: with SMTP id m18mr15112638qtx.231.1628691971351;
Wed, 11 Aug 2021 07:26:11 -0700 (PDT)
X-Received: by 2002:a37:9bc1:: with SMTP id d184mr3249893qke.400.1628691971213;
Wed, 11 Aug 2021 07:26:11 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!4.us.feeder.erje.net!2.eu.feeder.erje.net!feeder.erje.net!fdn.fr!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: Wed, 11 Aug 2021 07:26:10 -0700 (PDT)
In-Reply-To: <87tujwgldp.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=199.203.251.52; posting-account=ow8VOgoAAAAfiGNvoH__Y4ADRwQF1hZW
NNTP-Posting-Host: 199.203.251.52
References: <s9iea5$n5c$1@dont-email.me> <see71a$gk4$1@dont-email.me>
<seebtt$jrq$1@dont-email.me> <CjzOI.1030$Bg6.61@fx42.iad> <seejf8$9ti$1@dont-email.me>
<WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me>
<CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me> <87czqnlp2m.fsf@bsb.me.uk>
<WFWPI.1865$un2.1665@fx04.iad> <FiCQI.401$uk4.259@fx20.iad>
<poCQI.37363$EF2.25668@fx47.iad> <VNCQI.5685$Ug5.514@fx24.iad>
<seuu75$il3$1@dont-email.me> <TEEQI.5686$Ug5.143@fx24.iad>
<sf021q$78n$1@z-news.wcss.wroc.pl> <875ywci8k0.fsf@bsb.me.uk>
<63773d19-8176-43a0-9c6d-47f72b1e1c10n@googlegroups.com> <87tujwgldp.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <abc90066-026b-489d-9792-596e584c0af1n@googlegroups.com>
Subject: Re: Why does C allow structs to have a tag?
From: already5...@yahoo.com (Michael S)
Injection-Date: Wed, 11 Aug 2021 14:26:11 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Michael S - Wed, 11 Aug 2021 14:26 UTC

On Wednesday, August 11, 2021 at 4:29:52 PM UTC+3, Ben Bacarisse wrote:
> Michael S <already...@yahoo.com> writes:
>
> > On Wednesday, August 11, 2021 at 1:23:55 PM UTC+3, Ben Bacarisse wrote:
> >> anti...@math.uni.wroc.pl writes:
> >>
> >> > DFS <nos...@dfs.com> wrote:
> >> <cut>
> >> >> =================================================================
> >> >>
> >> >> //option 1: one puts per line (suggested by bart)
> >> >> int i = 0;
> >> >> char buff[longword+3];
> >> >> char line[tcols];
> >> >> *line = '\0';
> >> >> while(i < matchcnt) {
> >> >> for(int j = 1;j<=maxcols;j++) {
> >> >> sprintf(buff,"%-*s ",longword,matchwords[i++]);
> >> >> strcat(line,buff);
> >> >> }
> >> >> puts(line);
> >> >> *buff = '\0';
> >> >> *line = '\0';
> >> >> }
> >> >>
> >> >> =================================================================
> >> >>
> >> >> //option 2: one big string, one puts (per Lurndal)
> >> >> static char line[10000000]; //declared outside the func
> >> >>
> >> >> int i = 0;
> >> >> char buff[longword+3];
> >> >> *line = '\0';
> >> >> while(i < matchcnt) {
> >> >> for(int j = 1;j<=maxcols;j++) {
> >> >> sprintf(buff,"%-*s ",longword,matchwords[i++]);
> >> >> strcat(line,buff);
> >> > ^^^^^^^^^^^^^^^^^^
> >> >> }
> >> >> *buff = '\0';
> >> >> strcat(line,"\n");
> >> >> }
> >> >> puts(line);
> >> >>
> >> >> =================================================================
> >> >
> >> > The 'strcat' in a loop is classic antipattern: it causes quadratic
> >> > complexity to to repeated scanning for end of 'line'. Use something
> >> > like
> >> >
> >> > char * cp = line;
> >> > .....
> >> > strcat(cp, buff);
> >> > cp += strlen(buff);
> >> > ....
> >> ... or get the length first and use memcpy. But my favourite is
> >>
> >> cp += snprintf(cp, "%s", whatever);
> >>
> >> --
> >> Ben.
> >
> > Don't you mean sprintf() ?
> Yes, thanks. Finger memory making me type letters.
> > snprintf() requires one more parameter (size of the target buffer) and
> > does *not* return the number of actually written characters when
> > buffer is too small.
> snprintf is, in fact, what one usually wants to avoid making assumptions
> about available space (hence my urge to type it!) but the pattern
> becomes more complex in portable code because you can't write this:
>
> while (cp < ep) cp += snprintf(cp, ep - cp, "%s", whatever);
>
> because the construction of the pointer (and the subsequent comparison)
> are undefined. Once the pattern gets more complicated, other options
> start to look simpler.
>
> --
> Ben.

The code below is what I have in majority of my embedded projects.
May be, not 100% portable, by I don't care even about 25% portability. If it works on 1-2-3-4 targets that I care about, I am satisfied.
The purpose of my_pritntf() is to prevent buffer overflows (when used in code patterns similar to one you illustrated above) rather than to always output something meaningful.
For systems in question, it tends to be used in "nice to have" parts like telnet and web interfaces that are mostly used during development. For core functionality I try to impose anti-Doug-McIlroy principles, i.e. avoid both text inputs and text outputs. Not 100% successfully, last years one client in one small project insisted on JASON-based main COMM protocol, but that's a rare exception.

#include <stdio.h>
#include <limits.h>
#include <stdarg.h>

#include "my_snprintf.h"

// my_snprintf - Write formatted output to sized buffer
// my_snprintf is similar to snprintf() with following modifications
// 1. Argument n is signed. For n <= 0 the function does nothing and returns 0
// 2. Return value is always a number of characters that have been into s,
// not counting the terminating null character.
// The rest of description applies to case of positive n.
// Unlike snprintf(), if an encoding error occurs, a 0 is returned and
// the terminating null character is written to s[0].
// Unlike snprintf(), if n had not been sufficiently large, a value of n-1
// is returned and the terminating null character is written to s[n-1].
int
my_snprintf(char * s, ptrdiff_t n, const char * format, ...)
{ if (n <= 0)
return 0;
if (n > INT_MAX)
n = INT_MAX;

va_list args;
va_start(args, format);
int ret = vsnprintf(s, n, format, args);
if (ret < 0)
{ // encoding error.
// since our code uses no UNICODE, it should never happen, but let's handle it nevertheless
s[0] = 0; // may be, unnecessary
return 0;
}

if (ret >= n) {
s[n-1] = 0; // most likely unnecessary
return n-1;
}

return ret;
}

Re: Why does C allow structs to have a tag?

<5d8700fd-6ba7-4c72-ae2f-1d4ea91fe823n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:7141:: with SMTP id m62mr34722029qkc.496.1628694094041; Wed, 11 Aug 2021 08:01:34 -0700 (PDT)
X-Received: by 2002:a05:6214:e4e:: with SMTP id o14mr23309921qvc.55.1628694093898; Wed, 11 Aug 2021 08:01:33 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!4.us.feeder.erje.net!2.eu.feeder.erje.net!feeder.erje.net!news.uzoreto.com!tr3.eu1.usenetexpress.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.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: Wed, 11 Aug 2021 08:01:33 -0700 (PDT)
In-Reply-To: <GCQQI.17254$lK.16624@fx41.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:c0:8f45:e692:2f70; posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:c0:8f45:e692:2f70
References: <s9iea5$n5c$1@dont-email.me> <see71a$gk4$1@dont-email.me> <seebtt$jrq$1@dont-email.me> <CjzOI.1030$Bg6.61@fx42.iad> <seejf8$9ti$1@dont-email.me> <WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me> <CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me> <87czqnlp2m.fsf@bsb.me.uk> <WFWPI.1865$un2.1665@fx04.iad> <FiCQI.401$uk4.259@fx20.iad> <poCQI.37363$EF2.25668@fx47.iad> <VNCQI.5685$Ug5.514@fx24.iad> <seuu75$il3$1@dont-email.me> <TEEQI.5686$Ug5.143@fx24.iad> <GCQQI.17254$lK.16624@fx41.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5d8700fd-6ba7-4c72-ae2f-1d4ea91fe823n@googlegroups.com>
Subject: Re: Why does C allow structs to have a tag?
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Wed, 11 Aug 2021 15:01:34 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 12
 by: Malcolm McLean - Wed, 11 Aug 2021 15:01 UTC

On Wednesday, 11 August 2021 at 14:52:54 UTC+1, Scott Lurndal wrote:
>
> strcat is almost never the right interface to use. It needs
> to scan the entire string to find the terminal nul-byte before
> appending. As the string gets longer, each strcat takes longer
> than the one before.
>
> Just keep a pointer to the next element and increment the
> pointer each time you add a new element.
>
Most strings are short. Building up a url with strcat is not going to
stress a 3GHz machine. If the strings become huge then, yes, you
need to look at more efficient ways of concatenating them.

Re: Why does C allow structs to have a tag?

<PHRQI.5464$xY.2133@fx05.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!4.us.feeder.erje.net!2.eu.feeder.erje.net!feeder.erje.net!news.uzoreto.com!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx05.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Why does C allow structs to have a tag?
Newsgroups: comp.lang.c
References: <s9iea5$n5c$1@dont-email.me> <seejf8$9ti$1@dont-email.me> <WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me> <CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me> <87czqnlp2m.fsf@bsb.me.uk> <WFWPI.1865$un2.1665@fx04.iad> <FiCQI.401$uk4.259@fx20.iad> <poCQI.37363$EF2.25668@fx47.iad> <VNCQI.5685$Ug5.514@fx24.iad> <seuu75$il3$1@dont-email.me> <TEEQI.5686$Ug5.143@fx24.iad> <GCQQI.17254$lK.16624@fx41.iad> <5d8700fd-6ba7-4c72-ae2f-1d4ea91fe823n@googlegroups.com>
Lines: 18
Message-ID: <PHRQI.5464$xY.2133@fx05.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 11 Aug 2021 15:06:23 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 11 Aug 2021 15:06:23 GMT
X-Received-Bytes: 1871
 by: Scott Lurndal - Wed, 11 Aug 2021 15:06 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>On Wednesday, 11 August 2021 at 14:52:54 UTC+1, Scott Lurndal wrote:
>>
>> strcat is almost never the right interface to use. It needs
>> to scan the entire string to find the terminal nul-byte before
>> appending. As the string gets longer, each strcat takes longer
>> than the one before.
>>
>> Just keep a pointer to the next element and increment the
>> pointer each time you add a new element.
>>
>Most strings are short. Building up a url with strcat is not going to
>stress a 3GHz machine. If the strings become huge then, yes, you
>need to look at more efficient ways of concatenating them.

Building it with snprintf() will be far more flexible and efficient.

Every cycle matters.

Re: Why does C allow structs to have a tag?

<sf0re4$v91$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Wed, 11 Aug 2021 16:47:08 +0100
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <sf0re4$v91$1@dont-email.me>
References: <s9iea5$n5c$1@dont-email.me> <seejf8$9ti$1@dont-email.me>
<WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me>
<CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me>
<87czqnlp2m.fsf@bsb.me.uk> <WFWPI.1865$un2.1665@fx04.iad>
<FiCQI.401$uk4.259@fx20.iad> <poCQI.37363$EF2.25668@fx47.iad>
<VNCQI.5685$Ug5.514@fx24.iad> <seuu75$il3$1@dont-email.me>
<TEEQI.5686$Ug5.143@fx24.iad> <GCQQI.17254$lK.16624@fx41.iad>
<5d8700fd-6ba7-4c72-ae2f-1d4ea91fe823n@googlegroups.com>
<PHRQI.5464$xY.2133@fx05.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 11 Aug 2021 15:47:16 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ebac4182797cc3b1d63c47001b000224";
logging-data="32033"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+4uZ3y+/mkzRBv+xktO5lVNUAunlefYn4="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:7rur8INWcM1TBY1mDkv9C7nmv90=
In-Reply-To: <PHRQI.5464$xY.2133@fx05.iad>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210811-2, 11/8/2021), Outbound message
 by: Bart - Wed, 11 Aug 2021 15:47 UTC

On 11/08/2021 16:06, Scott Lurndal wrote:
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>> On Wednesday, 11 August 2021 at 14:52:54 UTC+1, Scott Lurndal wrote:
>>>
>>> strcat is almost never the right interface to use. It needs
>>> to scan the entire string to find the terminal nul-byte before
>>> appending. As the string gets longer, each strcat takes longer
>>> than the one before.
>>>
>>> Just keep a pointer to the next element and increment the
>>> pointer each time you add a new element.
>>>
>> Most strings are short. Building up a url with strcat is not going to
>> stress a 3GHz machine. If the strings become huge then, yes, you
>> need to look at more efficient ways of concatenating them.
>
> Building it with snprintf() will be far more flexible and efficient.
>
> Every cycle matters.
>

Start with this:

char str[100];
char* s;

Then a loop like this (all unoptimised code to stop it being optimised
out of existence):

for (int i=0; i<10000000; ++i) {
strcpy(str,"one ");
strcat(str,"two ");
strcat(str,"three ");
strcat(str,"four ");
strcat(str,"five");
}
puts(str);

took 1 second (on my Windows PC running tcc). If use sprintf():

for (int i=0; i<10000000; ++i) {
s=str;
s+=sprintf(s,"%s","one ");
s+=sprintf(s,"%s","two ");
s+=sprintf(s,"%s","three ");
s+=sprintf(s,"%s","four ");
sprintf(s,"%s","five");
}
puts(s);

then it takes 5.5 seconds. With snprintf() as you suggest, it takes 6.1
seconds. I thought you said every cycle matters?

These all write into the same string. If each iteration uses a newly
allocated 100-char string, then the strcat loop takes 2.2 seconds, and
both forms of sprintf take something over 7 seconds.

If I take the second loop above, and write the string directly (so not
using "%s"), then it makes no difference; it's not the formatting that
takes the extra time, not for %s anyway, it must be other overheads.

Re: Why does C allow structs to have a tag?

<kHSQI.38629$EF2.24792@fx47.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx47.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Why does C allow structs to have a tag?
Newsgroups: comp.lang.c
References: <s9iea5$n5c$1@dont-email.me> <sembba$oul$1@dont-email.me> <CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me> <87czqnlp2m.fsf@bsb.me.uk> <WFWPI.1865$un2.1665@fx04.iad> <FiCQI.401$uk4.259@fx20.iad> <poCQI.37363$EF2.25668@fx47.iad> <VNCQI.5685$Ug5.514@fx24.iad> <seuu75$il3$1@dont-email.me> <TEEQI.5686$Ug5.143@fx24.iad> <GCQQI.17254$lK.16624@fx41.iad> <5d8700fd-6ba7-4c72-ae2f-1d4ea91fe823n@googlegroups.com> <PHRQI.5464$xY.2133@fx05.iad> <sf0re4$v91$1@dont-email.me>
Lines: 27
Message-ID: <kHSQI.38629$EF2.24792@fx47.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 11 Aug 2021 16:14:08 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 11 Aug 2021 16:14:08 GMT
X-Received-Bytes: 2088
 by: Scott Lurndal - Wed, 11 Aug 2021 16:14 UTC

Bart <bc@freeuk.com> writes:
>On 11/08/2021 16:06, Scott Lurndal wrote:
>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>>> On Wednesday, 11 August 2021 at 14:52:54 UTC+1, Scott Lurndal wrote:
>>>>
>>>> strcat is almost never the right interface to use. It needs
>>>> to scan the entire string to find the terminal nul-byte before
>>>> appending. As the string gets longer, each strcat takes longer
>>>> than the one before.
>>>>
>>>> Just keep a pointer to the next element and increment the
>>>> pointer each time you add a new element.
>>>>
>>> Most strings are short. Building up a url with strcat is not going to
>>> stress a 3GHz machine. If the strings become huge then, yes, you
>>> need to look at more efficient ways of concatenating them.
>>
>> Building it with snprintf() will be far more flexible and efficient.
>>
>> Every cycle matters.
>>
>
>
>Start with this:

No thanks. I've enough to do writing real working production code.

Re: Why does C allow structs to have a tag?

<sf10rj$7g9$1@z-news.wcss.wroc.pl>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!newsfeed.pionier.net.pl!pwr.wroc.pl!news.wcss.wroc.pl!not-for-mail
From: antis...@math.uni.wroc.pl
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Wed, 11 Aug 2021 17:19:47 +0000 (UTC)
Organization: Politechnika Wroclawska
Lines: 85
Message-ID: <sf10rj$7g9$1@z-news.wcss.wroc.pl>
References: <s9iea5$n5c$1@dont-email.me> <seebtt$jrq$1@dont-email.me> <CjzOI.1030$Bg6.61@fx42.iad> <seejf8$9ti$1@dont-email.me> <WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me> <CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me> <87czqnlp2m.fsf@bsb.me.uk> <sepbrd$vg4$1@dont-email.me> <877dgvljpf.fsf@bsb.me.uk> <2a1b4347-595a-469a-8df1-db64af9896acn@googlegroups.com> <Wg_PI.6656$NQ1.5159@fx48.iad> <94f47c65-5f5f-44d1-bc37-d51155624ae5n@googlegroups.com> <sesbbk$63q$1@dont-email.me>
NNTP-Posting-Host: hera.math.uni.wroc.pl
X-Trace: z-news.wcss.wroc.pl 1628702387 7689 156.17.86.1 (11 Aug 2021 17:19:47 GMT)
X-Complaints-To: abuse@news.pwr.wroc.pl
NNTP-Posting-Date: Wed, 11 Aug 2021 17:19:47 +0000 (UTC)
Cancel-Lock: sha1:pv9dAOriJz+yyGYPOupabeV44Cw=
User-Agent: tin/2.4.3-20181224 ("Glen Mhor") (UNIX) (Linux/4.19.0-10-amd64 (x86_64))
X-Received-Bytes: 5016
 by: antis...@math.uni.wroc.pl - Wed, 11 Aug 2021 17:19 UTC

Bart <bc@freeuk.com> wrote:
> On 09/08/2021 09:29, Michael S wrote:
> > On Monday, August 9, 2021 at 3:03:15 AM UTC+3, DFS wrote:
> >> On 8/8/2021 6:30 PM, Michael S wrote:
> >>
> >>> Bart and DFS are unique people with unique capabilities. DFS more so,
> >> What are you babbling about?
> >
> > Your shared love to strange tools that wouldn't in top#5 list of choice of professional and likely not in top#10.
>
> You just don't get it.
>
> When I drive to the shops I like to use my hatchback, I don't need a
> 40-ton truck, or a 747, which are how big and cumbersome those
> professional tools appear to me. (And if younger I'd jump on my bike.)
>
> Who cares about the top 10 anyway? Where was the top 10 when I needed a
> tiny, fast HLL language for my 8-bit micros which actually ran ON those
> same micros? I've used my own languages ever since.
>
> And when I have to play with C, I prefer my own small C compiler; you
> know, that one with the faster printf than gcc/tdm.

I like small and fast programs. But here it looks like
you really want to mislead other folks. First, what
you are measuring is speed of Windows console. IIUC
correctly what you wrote in your case Windows console
is fast enough: if you read printed text time spent
in console will be negligible compared to time spent
reading. And if console were too slow simple way
to solve problem is to get faster console: AFAICS
other folks pointed out that Microsoft provides
faster console and consoles from third party
(Cygwin and Msys) are faster too.

Second, any semi-decent tool to measure exection
time will tell you that time spent in your program
is negligible and basically 100% of time is
spent in Windows console. But instead of telling
that Windows console has a quirk which make it
much slower with one way of driving it (which
happen to be used by your gcc/tdm package) you
spin it as "gcc is slower than tcc".

Third, every programmer must understand importance
of being precise: programmer job is tell computer
what to do and if programer is not precise
enough computer will reject the task or do wrong
thing. Other explaned you difference between
gcc and package that you get. This distinction
matters because it tells you where to report
problem. In your case, if you honestly do
not know which part is responsible, then it
is resonable to report problems to whoever is
behind TDM project. OTOH, if you think that
problem is in core gcc, then it is resonable
to report it to gcc folks (since your version
is quite old you may get answer "fixed in
newer release", but that is another topic).
If you identify specific library or tool it
makes sense to report problem to authors
of problematic components.

If report to gcc folks problem with Windows console,
do not expect nice answer: it is not part that
they supply.

Forth, you are jumping to conclusion: you do not
know why printf in your gcc/tdm package is doing
output in the specific way. It may be a bug.
But to do this requires some effort, so there
may be deeper reason. Namely, Windows console
is quirky, and "slow" way may be reasonable
way to get correct output in all cases. I mean,
there are bugs where simple fix is to force
"slow" mode of operation. If "slow" mode is
fast enough, then this may be resonable fix
(fast enoug correct program is much better than
much faster incorrect one). Note: I do not have
specific info, but AFAICS you too do not know why
this is done. Before knowing reasons claim like
"printf gcc/tdm in slower" are jumping to conclusion.

--
Waldek Hebisch

Re: Why does C allow structs to have a tag?

<sf11ab$bfr$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Wed, 11 Aug 2021 18:27:32 +0100
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <sf11ab$bfr$1@dont-email.me>
References: <s9iea5$n5c$1@dont-email.me> <sembba$oul$1@dont-email.me>
<CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me>
<87czqnlp2m.fsf@bsb.me.uk> <WFWPI.1865$un2.1665@fx04.iad>
<FiCQI.401$uk4.259@fx20.iad> <poCQI.37363$EF2.25668@fx47.iad>
<VNCQI.5685$Ug5.514@fx24.iad> <seuu75$il3$1@dont-email.me>
<TEEQI.5686$Ug5.143@fx24.iad> <GCQQI.17254$lK.16624@fx41.iad>
<5d8700fd-6ba7-4c72-ae2f-1d4ea91fe823n@googlegroups.com>
<PHRQI.5464$xY.2133@fx05.iad> <sf0re4$v91$1@dont-email.me>
<kHSQI.38629$EF2.24792@fx47.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 11 Aug 2021 17:27:39 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ebac4182797cc3b1d63c47001b000224";
logging-data="11771"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18EI2gmvYQW6WDilrng5c1L2MOr36fgpT4="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:WPDpFyJnxjKJ5TZjv3+FLPd5siQ=
In-Reply-To: <kHSQI.38629$EF2.24792@fx47.iad>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210811-2, 11/8/2021), Outbound message
 by: Bart - Wed, 11 Aug 2021 17:27 UTC

On 11/08/2021 17:14, Scott Lurndal wrote:
> Bart <bc@freeuk.com> writes:
>> On 11/08/2021 16:06, Scott Lurndal wrote:
>>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>>>> On Wednesday, 11 August 2021 at 14:52:54 UTC+1, Scott Lurndal wrote:
>>>>>
>>>>> strcat is almost never the right interface to use. It needs
>>>>> to scan the entire string to find the terminal nul-byte before
>>>>> appending. As the string gets longer, each strcat takes longer
>>>>> than the one before.
>>>>>
>>>>> Just keep a pointer to the next element and increment the
>>>>> pointer each time you add a new element.
>>>>>
>>>> Most strings are short. Building up a url with strcat is not going to
>>>> stress a 3GHz machine. If the strings become huge then, yes, you
>>>> need to look at more efficient ways of concatenating them.
>>>
>>> Building it with snprintf() will be far more flexible and efficient.
>>>
>>> Every cycle matters.
>>>
>>
>>
>> Start with this:
>
> No thanks. I've enough to do writing real working production code.
>

And giving bad, untested advice...

Re: Why does C allow structs to have a tag?

<fc51810f-a1c6-44a5-9dbd-87368dda1df9n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:9e12:: with SMTP id h18mr114013qke.269.1628703595131; Wed, 11 Aug 2021 10:39:55 -0700 (PDT)
X-Received: by 2002:ae9:f201:: with SMTP id m1mr103343qkg.381.1628703594996; Wed, 11 Aug 2021 10:39:54 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!tr1.eu1.usenetexpress.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.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: Wed, 11 Aug 2021 10:39:54 -0700 (PDT)
In-Reply-To: <PHRQI.5464$xY.2133@fx05.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:8045:541d:1148:bcd9; posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:8045:541d:1148:bcd9
References: <s9iea5$n5c$1@dont-email.me> <seejf8$9ti$1@dont-email.me> <WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me> <CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me> <87czqnlp2m.fsf@bsb.me.uk> <WFWPI.1865$un2.1665@fx04.iad> <FiCQI.401$uk4.259@fx20.iad> <poCQI.37363$EF2.25668@fx47.iad> <VNCQI.5685$Ug5.514@fx24.iad> <seuu75$il3$1@dont-email.me> <TEEQI.5686$Ug5.143@fx24.iad> <GCQQI.17254$lK.16624@fx41.iad> <5d8700fd-6ba7-4c72-ae2f-1d4ea91fe823n@googlegroups.com> <PHRQI.5464$xY.2133@fx05.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fc51810f-a1c6-44a5-9dbd-87368dda1df9n@googlegroups.com>
Subject: Re: Why does C allow structs to have a tag?
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Wed, 11 Aug 2021 17:39:55 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 15
 by: Malcolm McLean - Wed, 11 Aug 2021 17:39 UTC

On Wednesday, 11 August 2021 at 16:06:38 UTC+1, Scott Lurndal wrote:
>
> Building it with snprintf() will be far more flexible and efficient.
>
> Every cycle matters.
>
People often talk about "bottlenecks" in code. However for a program
which launches, performs a calculation, returns a result, and terminates,
there are no bottlenecks. Every cycle is equal. However not every line of
code is equal. Typically some lines will be executed millions or even
billions of times, other lines only once.

But a lot of programs don't fit that model. They spend a lot of time idling,
waiting for input, and then occasionally present the user with a lag when a
long operation is attempted. Efficiency only matters in the laggy code,
there's no point in optimising code which executes in under just noticeable time.

Re: Why does C allow structs to have a tag?

<a7UQI.5572$xY.366@fx05.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
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!fx05.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Why does C allow structs to have a tag?
Newsgroups: comp.lang.c
References: <s9iea5$n5c$1@dont-email.me> <CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me> <87czqnlp2m.fsf@bsb.me.uk> <WFWPI.1865$un2.1665@fx04.iad> <FiCQI.401$uk4.259@fx20.iad> <poCQI.37363$EF2.25668@fx47.iad> <VNCQI.5685$Ug5.514@fx24.iad> <seuu75$il3$1@dont-email.me> <TEEQI.5686$Ug5.143@fx24.iad> <GCQQI.17254$lK.16624@fx41.iad> <5d8700fd-6ba7-4c72-ae2f-1d4ea91fe823n@googlegroups.com> <PHRQI.5464$xY.2133@fx05.iad> <fc51810f-a1c6-44a5-9dbd-87368dda1df9n@googlegroups.com>
Lines: 22
Message-ID: <a7UQI.5572$xY.366@fx05.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 11 Aug 2021 17:52:06 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 11 Aug 2021 17:52:06 GMT
X-Received-Bytes: 2204
 by: Scott Lurndal - Wed, 11 Aug 2021 17:52 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>On Wednesday, 11 August 2021 at 16:06:38 UTC+1, Scott Lurndal wrote:
>>
>> Building it with snprintf() will be far more flexible and efficient.
>>
>> Every cycle matters.
>>
>People often talk about "bottlenecks" in code. However for a program
>which launches, performs a calculation, returns a result, and terminates,
>there are no bottlenecks. Every cycle is equal. However not every line of
>code is equal. Typically some lines will be executed millions or even
>billions of times, other lines only once.
>
>But a lot of programs don't fit that model. They spend a lot of time idling,
>waiting for input, and then occasionally present the user with a lag when a
>long operation is attempted. Efficiency only matters in the laggy code,
>there's no point in optimising code which executes in under just noticeable time.

You are discounting the fact that prodiction code is generally not running
stand-alone bare-metal. In which case there will be other
processes/threads/guests waiting for the CPU, so every cycle matters.

Re: Why does C allow structs to have a tag?

<sf1399$mg3$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Wed, 11 Aug 2021 11:01:12 -0700
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <sf1399$mg3$1@dont-email.me>
References: <s9iea5$n5c$1@dont-email.me> <seejf8$9ti$1@dont-email.me>
<WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me>
<CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me>
<87czqnlp2m.fsf@bsb.me.uk> <WFWPI.1865$un2.1665@fx04.iad>
<FiCQI.401$uk4.259@fx20.iad> <poCQI.37363$EF2.25668@fx47.iad>
<VNCQI.5685$Ug5.514@fx24.iad> <seuu75$il3$1@dont-email.me>
<TEEQI.5686$Ug5.143@fx24.iad> <GCQQI.17254$lK.16624@fx41.iad>
<5d8700fd-6ba7-4c72-ae2f-1d4ea91fe823n@googlegroups.com>
<PHRQI.5464$xY.2133@fx05.iad> <sf0re4$v91$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 11 Aug 2021 18:01:13 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="14411caeb0189d6045f9afc5e45e7575";
logging-data="23043"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18LBCFTf0s0cRYedpZoxClE"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.12.0
Cancel-Lock: sha1:/a8lkyTby/SXcWEsyaHAjk2Xuf0=
In-Reply-To: <sf0re4$v91$1@dont-email.me>
Content-Language: en-US
 by: Andrey Tarasevich - Wed, 11 Aug 2021 18:01 UTC

On 8/11/2021 8:47 AM, Bart wrote:
>
> (all unoptimised code to stop it being optimised
> out of existence):
> ...
> then it takes 5.5 seconds. With snprintf() as you suggest, it takes 6.1
> seconds. I thought you said every cycle matters?
>

^^^ Timing "unoptimised" code and then talking about "cycles". This does
not make a single shred of sense.

--
Best regards,
Andrey Tarasevich

Re: Why does C allow structs to have a tag?

<9GUQI.8728$Bg6.71@fx42.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!peer02.ams4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx42.iad.POSTED!not-for-mail
From: nos...@dfs.com (DFS)
Subject: Re: Why does C allow structs to have a tag?
Newsgroups: comp.lang.c
References: <s9iea5$n5c$1@dont-email.me> <see71a$gk4$1@dont-email.me>
<seebtt$jrq$1@dont-email.me> <CjzOI.1030$Bg6.61@fx42.iad>
<seejf8$9ti$1@dont-email.me> <WowPI.4743$NQ1.1007@fx48.iad>
<sembba$oul$1@dont-email.me> <CrQPI.669$bS5.239@fx21.iad>
<seoqf4$pj7$1@dont-email.me> <87czqnlp2m.fsf@bsb.me.uk>
<WFWPI.1865$un2.1665@fx04.iad> <FiCQI.401$uk4.259@fx20.iad>
<poCQI.37363$EF2.25668@fx47.iad> <VNCQI.5685$Ug5.514@fx24.iad>
<seuu75$il3$1@dont-email.me> <TEEQI.5686$Ug5.143@fx24.iad>
<sf021q$78n$1@z-news.wcss.wroc.pl>
X-Mozilla-News-Host: news://usnews.blocknews.net
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
MIME-Version: 1.0
In-Reply-To: <sf021q$78n$1@z-news.wcss.wroc.pl>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
Lines: 129
Message-ID: <9GUQI.8728$Bg6.71@fx42.iad>
X-Complaints-To: abuse@blocknews.net
NNTP-Posting-Date: Wed, 11 Aug 2021 18:29:25 UTC
Organization: blocknews - www.blocknews.net
Date: Wed, 11 Aug 2021 14:29:24 -0400
X-Received-Bytes: 4579
 by: DFS - Wed, 11 Aug 2021 18:29 UTC

On 8/11/2021 4:34 AM, antispam@math.uni.wroc.pl wrote:

> The 'strcat' in a loop is classic antipattern: it causes quadratic
> complexity to to repeated scanning for end of 'line'. Use something
> like
>
> char * cp = line;
> .....
> strcat(cp, buff);
> cp += strlen(buff);
> ....
>

From other posts:

> Bacarisse: "my favourite is cp += snprintf(cp, "%s", whatever);"
> (he meant to say sprintf)

> Lurndal: "Building it with snprintf() will be far more flexible and
> efficient."

build string, in seconds
----------------------------- build +
antispam sprintf()/ print to
substring matches strcat as above snprintf() screen

catt 91 0.036 0.036 0.036 0.037
cat 3710 0.067 0.038 0.038 0.129
ca 22793 1.423 0.044 0.052 0.657
c 128689 53.591 0.084 0.139 4.437
e 252896 207.782 0.132 0.238 8.598

Much better! Thanks for the suggestions.

built on Win10, using Mingw-w64 GCC
http://mingw-w64.org/doku.php

which I got via
https://github.com/skeeto/w64devkit/releases/tag/v1.8.0

run in cmd.exe shell inside ConEmu

$ prog wordlist.txt option1234 (for dev and testing)

===========================================================================
//print matching words in columns of the same size, with no line
// wrapping in middle of word

//array large enough to output 370K words of length 31
static char line[12000000];

void showresults(char *matchwords[], int matchcnt, int stropt) {
//get longest word in results
int longword = 0;
for(int i=0;i<matchcnt;i++) {
int thislen = strlen(matchwords[i]);
if(thislen>longword) {longword=thislen; }
}
//get # of columns visible onscreen
int tcols = gettcols();
//get max number of columns to print on each line
//add 2 to longword to account for spaces
int maxcols = ((int)(tcols/(longword+2)));
//build one big string, do one puts
//fastest but requires huge array alloc
int i = 0;
char buff[longword+3];
*line = '\0';
char *cp = line;
while(i < matchcnt) {
for(int j = 1;j<=maxcols;j++) {

//add word to buffer
sprintf(buff,"%-*s ",longword,matchwords[i++]);

//add buffer to string

//strcat
if(stropt == 1) {
strcat(line,buff);
}

//antispam/strlen
else if(stropt == 2) {
strcat(cp, buff);
cp += strlen(buff);
}

//sprintf
else if(stropt == 3) {
cp += sprintf(cp, "%s", buff);
}

//snprintf
else if(stropt == 4) {
cp += snprintf(cp, sizeof buff, "%s", buff);
}

}

//reset buffer
*buff = '\0';

//add newline
if(stropt == 1) //strcat
strcat(line,"\n");
else
cp += sprintf(cp, "\n");

}
//print to screen
puts(line);

//show string builder option
char *stropts[] = {"strcat","antispam/strlen","sprintf","snprintf"};
printf("%s\n",stropts[stropt-1]);

}
===========================================================================

Re: Why does C allow structs to have a tag?

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

  copy mid

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

  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: Why does C allow structs to have a tag?
Date: Wed, 11 Aug 2021 11:41:23 -0700
Organization: None to speak of
Lines: 34
Message-ID: <87lf57j030.fsf@nosuchdomain.example.com>
References: <s9iea5$n5c$1@dont-email.me> <seejf8$9ti$1@dont-email.me>
<WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me>
<CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me>
<87czqnlp2m.fsf@bsb.me.uk> <WFWPI.1865$un2.1665@fx04.iad>
<FiCQI.401$uk4.259@fx20.iad> <poCQI.37363$EF2.25668@fx47.iad>
<VNCQI.5685$Ug5.514@fx24.iad> <seuu75$il3$1@dont-email.me>
<TEEQI.5686$Ug5.143@fx24.iad> <GCQQI.17254$lK.16624@fx41.iad>
<5d8700fd-6ba7-4c72-ae2f-1d4ea91fe823n@googlegroups.com>
<PHRQI.5464$xY.2133@fx05.iad>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="7af0248d926c60a6cf88b66f75a520dd";
logging-data="11204"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ahdFo1xlqc1YG//ptsJUJ"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:vAVn0xuxbiLaOCRJ5cJRjf/NAzE=
sha1:Gve5mJ7KhTh8SCjIQbT2A5h39/M=
 by: Keith Thompson - Wed, 11 Aug 2021 18:41 UTC

scott@slp53.sl.home (Scott Lurndal) writes:
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>>On Wednesday, 11 August 2021 at 14:52:54 UTC+1, Scott Lurndal wrote:
>>>
>>> strcat is almost never the right interface to use. It needs
>>> to scan the entire string to find the terminal nul-byte before
>>> appending. As the string gets longer, each strcat takes longer
>>> than the one before.
>>>
>>> Just keep a pointer to the next element and increment the
>>> pointer each time you add a new element.
>>>
>>Most strings are short. Building up a url with strcat is not going to
>>stress a 3GHz machine. If the strings become huge then, yes, you
>>need to look at more efficient ways of concatenating them.
>
> Building it with snprintf() will be far more flexible and efficient.
>
> Every cycle matters.

As Bart's measurements indicate, snprintf() is likely to have
substantial overhead, probably because it has to parse its format
string. I wouldn't assume snprintf() is going to be faster than
strcat() without measuring it for the specific data I'm working with.

The non-standard strlcat() returns the initial length of the destination
plus the length of the source, which can be used to find the end of the
copyied string without re-scanning. (It can be a little tricky to get
the compilation command right on some systems.)

--
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: Why does C allow structs to have a tag?

<sf15rl$cia$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Wed, 11 Aug 2021 19:45:01 +0100
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <sf15rl$cia$1@dont-email.me>
References: <s9iea5$n5c$1@dont-email.me> <seejf8$9ti$1@dont-email.me>
<WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me>
<CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me>
<87czqnlp2m.fsf@bsb.me.uk> <WFWPI.1865$un2.1665@fx04.iad>
<FiCQI.401$uk4.259@fx20.iad> <poCQI.37363$EF2.25668@fx47.iad>
<VNCQI.5685$Ug5.514@fx24.iad> <seuu75$il3$1@dont-email.me>
<TEEQI.5686$Ug5.143@fx24.iad> <GCQQI.17254$lK.16624@fx41.iad>
<5d8700fd-6ba7-4c72-ae2f-1d4ea91fe823n@googlegroups.com>
<PHRQI.5464$xY.2133@fx05.iad> <sf0re4$v91$1@dont-email.me>
<sf1399$mg3$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 11 Aug 2021 18:45:09 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ebac4182797cc3b1d63c47001b000224";
logging-data="12874"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19dyxVAgQLY6HTFBHqg1ORzzChJVtbVUWo="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:w8i3jsG/UArLfQne4hwa47XJ2/o=
In-Reply-To: <sf1399$mg3$1@dont-email.me>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210811-2, 11/8/2021), Outbound message
 by: Bart - Wed, 11 Aug 2021 18:45 UTC

On 11/08/2021 19:01, Andrey Tarasevich wrote:
> On 8/11/2021 8:47 AM, Bart wrote:
>>
>> (all unoptimised code to stop it being optimised out of existence):
>> ...
>> then it takes 5.5 seconds. With snprintf() as you suggest, it takes
>> 6.1 seconds. I thought you said every cycle matters?
>>
>
> ^^^ Timing "unoptimised" code and then talking about "cycles". This does
> not make a single shred of sense.
>

The code we're talking about is functions in a binary library which
presumably are already optimised.

If I turn on optimisation for my simple loops, then all timings become
0.0 seconds; what on earth use is that?

Perhaps you'd like to provide a better test program then? One which
tests the efficacy of strcat vs snprintf, rather than a how smart a
compiler is in making short work of a pointless, repetitive loop.

In a real application, the strings may not be simple literals of a known
length, may not be so amenable to inlining, and may not be in a simple
loop like this and where results are discarded.

Re: Why does C allow structs to have a tag?

<r1VQI.5573$xY.4985@fx05.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!fdc2.netnews.com!news-out.netnews.com!news.alt.net!fdc3.netnews.com!feeder1.feed.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx05.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Why does C allow structs to have a tag?
Newsgroups: comp.lang.c
References: <s9iea5$n5c$1@dont-email.me> <CjzOI.1030$Bg6.61@fx42.iad> <seejf8$9ti$1@dont-email.me> <WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me> <CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me> <87czqnlp2m.fsf@bsb.me.uk> <WFWPI.1865$un2.1665@fx04.iad> <FiCQI.401$uk4.259@fx20.iad> <poCQI.37363$EF2.25668@fx47.iad> <VNCQI.5685$Ug5.514@fx24.iad> <seuu75$il3$1@dont-email.me> <TEEQI.5686$Ug5.143@fx24.iad> <sf021q$78n$1@z-news.wcss.wroc.pl> <9GUQI.8728$Bg6.71@fx42.iad>
Lines: 98
Message-ID: <r1VQI.5573$xY.4985@fx05.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 11 Aug 2021 18:54:15 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 11 Aug 2021 18:54:15 GMT
X-Received-Bytes: 3955
 by: Scott Lurndal - Wed, 11 Aug 2021 18:54 UTC

DFS <nospam@dfs.com> writes:
>On 8/11/2021 4:34 AM, antispam@math.uni.wroc.pl wrote:
>
>
>> The 'strcat' in a loop is classic antipattern: it causes quadratic
>> complexity to to repeated scanning for end of 'line'. Use something
>> like
>>
>> char * cp = line;
>> .....
>> strcat(cp, buff);
>> cp += strlen(buff);
>> ....
>>
>
> From other posts:
>
>> Bacarisse: "my favourite is cp += snprintf(cp, "%s", whatever);"
>> (he meant to say sprintf)
>
>> Lurndal: "Building it with snprintf() will be far more flexible and
>> efficient."
>
>
>
> build string, in seconds
> ----------------------------- build +
> antispam sprintf()/ print to
>substring matches strcat as above snprintf() screen
>
>catt 91 0.036 0.036 0.036 0.037
>cat 3710 0.067 0.038 0.038 0.129
>ca 22793 1.423 0.044 0.052 0.657
>c 128689 53.591 0.084 0.139 4.437
>e 252896 207.782 0.132 0.238 8.598
>
>
>Much better! Thanks for the suggestions.
>
>
>built on Win10, using Mingw-w64 GCC
>http://mingw-w64.org/doku.php
>
>which I got via
>https://github.com/skeeto/w64devkit/releases/tag/v1.8.0
>
>run in cmd.exe shell inside ConEmu
>
>$ prog wordlist.txt option1234 (for dev and testing)
>
>===========================================================================
>//print matching words in columns of the same size, with no line
>// wrapping in middle of word
>
>//array large enough to output 370K words of length 31
>static char line[12000000];
>
>void showresults(char *matchwords[], int matchcnt, int stropt) {
>

I was thinking more along the lines of this:
static char line[12000000];

/**
* Catenate the words from 'matchwords' into 'line', computing the
* word length of the longest single word along the way.
*
* @param matchwords A vector of character pointers, one for each word
* @param matchcnt The number of entries in the matchwords vector.
*/
void
showresults(char **matchwords, size_t matchcnt)
{ size_t longest_word = 0ul;
char *lp = line;
char *elp = &line[sizeof(line)];

for(size_t i = 0ul; i < matchcount; i++) {
char *cp = *matchwords++;
size_t len = 0ul;
while ((*cp != '\0') && (lp < elp)) {
len++;
*lp++ = *cp++;
}
longest_word = max(longest_word, len);
}

if (lp < elp) *lp++ = '\0';
else line[sizeof(line)-1] = '\0';

puts(line);
}

It will silently truncate the output string if 'line'
isn't large enough to collect all the words in 'matchwords'.

The implementation of max is left to the student.

Re: Why does C allow structs to have a tag?

<sf1712$t4a$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Wed, 11 Aug 2021 20:04:54 +0100
Organization: A noiseless patient Spider
Lines: 106
Message-ID: <sf1712$t4a$1@dont-email.me>
References: <s9iea5$n5c$1@dont-email.me> <seebtt$jrq$1@dont-email.me>
<CjzOI.1030$Bg6.61@fx42.iad> <seejf8$9ti$1@dont-email.me>
<WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me>
<CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me>
<87czqnlp2m.fsf@bsb.me.uk> <sepbrd$vg4$1@dont-email.me>
<877dgvljpf.fsf@bsb.me.uk>
<2a1b4347-595a-469a-8df1-db64af9896acn@googlegroups.com>
<Wg_PI.6656$NQ1.5159@fx48.iad>
<94f47c65-5f5f-44d1-bc37-d51155624ae5n@googlegroups.com>
<sesbbk$63q$1@dont-email.me> <sf10rj$7g9$1@z-news.wcss.wroc.pl>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 11 Aug 2021 19:05:07 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ebac4182797cc3b1d63c47001b000224";
logging-data="29834"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18/mGE4chqaNRFyom1nzhcfyV1UI5nYxBY="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:eH7gE+cZSWTEtcRggiHzHgy2hZA=
In-Reply-To: <sf10rj$7g9$1@z-news.wcss.wroc.pl>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210811-2, 11/8/2021), Outbound message
 by: Bart - Wed, 11 Aug 2021 19:04 UTC

On 11/08/2021 18:19, antispam@math.uni.wroc.pl wrote:
> Bart <bc@freeuk.com> wrote:

>> And when I have to play with C, I prefer my own small C compiler; you
>> know, that one with the faster printf than gcc/tdm.
>
> I like small and fast programs. But here it looks like
> you really want to mislead other folks.

I gave timings for bcc, tcc, gcc**, clang**, CL, DMC and lccwin.

There was a mixup over the ones marked ** which is explained below. But
some gcc/clang versions were much slower. lccwin was in between.

> First, what
> you are measuring is speed of Windows console. IIUC
> correctly what you wrote in your case Windows console
> is fast enough: if you read printed text time spent
> in console will be negligible compared to time spent
> reading. And if console were too slow simple way
> to solve problem is to get faster console: AFAICS
> other folks pointed out that Microsoft provides
> faster console and consoles from third party
> (Cygwin and Msys) are faster too.

That's not really relevant. All compilers were running the same program
under the same OS and with the same, bog-standard MS Command Prompt.

If one compiler exhibits much slower behaviour, then it's odd to suspect
the console first.

> Second, any semi-decent tool to measure exection
> time will tell you that time spent in your program
> is negligible and basically 100% of time is
> spent in Windows console. But instead of telling
> that Windows console has a quirk which make it
> much slower with one way of driving it (which
> happen to be used by your gcc/tdm package) you
> spin it as "gcc is slower than tcc".

DFS has observed the effect; I have observed it. Other who haven't
observed it haven't been using the same platform or the right compilers.

However I've just done another test, and it is only one specific gcc and
clang installation which has that problem, at least, of the ones I have.

So:

gcc/tdm 9.2.0 OK
clang/LLVM 11.0.0 OK
gcc/11.2.0 Slow, both of these from Winlib link
clang 12.0.1 Slow

The winlib gcc installs itself in such a way that it becomes the default
'gcc' version, and also confusingly provides clang.exe which then the
default 'clang'.

I'm now upgraded my gcc/tdm to 10.3.0, and that is slow too:

gcc/tdm 10.3.0 Slow (there is no clang)

So my comments about gcc/tdm having the problem, although made
erroneously, are actually correct.

> Third, every programmer must understand importance
> of being precise: programmer job is tell computer
> what to do and if programer is not precise
> enough computer will reject the task or do wrong
> thing. Other explaned you difference between
> gcc and package that you get. This distinction
> matters because it tells you where to report
> problem. In your case, if you honestly do
> not know which part is responsible, then it
> is resonable to report problems to whoever is
> behind TDM project.

If you look at my first post on the subject (8-8-21 15:41 BST) it was to
confirm what DFS had observed, and I suggested a workaround.

But everyone seems very keen to challenge what I'd said.

> OTOH, if you think that
> problem is in core gcc, then it is resonable
> to report it to gcc folks (since your version
> is quite old you may get answer "fixed in
> newer release", but that is another topic).
> If you identify specific library or tool it
> makes sense to report problem to authors
> of problematic components.

I really have no idea who's reponsible for what. And I don't care as
it's not my product so not my headache.

(It's also, now, exhibited on two separate builds: gcc/tdm 10.3.0, from
FSF Inc, and gcc 11.2.0 from chap called Brecht Sanders.)

> Forth, you are jumping to conclusion: you do not
> know why printf in your gcc/tdm package is doing
> output in the specific way.

No, I don't, but that's what it does.

Re: Why does C allow structs to have a tag?

<sf17aj$3gg$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Wed, 11 Aug 2021 20:10:04 +0100
Organization: A noiseless patient Spider
Lines: 109
Message-ID: <sf17aj$3gg$1@dont-email.me>
References: <s9iea5$n5c$1@dont-email.me> <CjzOI.1030$Bg6.61@fx42.iad>
<seejf8$9ti$1@dont-email.me> <WowPI.4743$NQ1.1007@fx48.iad>
<sembba$oul$1@dont-email.me> <CrQPI.669$bS5.239@fx21.iad>
<seoqf4$pj7$1@dont-email.me> <87czqnlp2m.fsf@bsb.me.uk>
<WFWPI.1865$un2.1665@fx04.iad> <FiCQI.401$uk4.259@fx20.iad>
<poCQI.37363$EF2.25668@fx47.iad> <VNCQI.5685$Ug5.514@fx24.iad>
<seuu75$il3$1@dont-email.me> <TEEQI.5686$Ug5.143@fx24.iad>
<sf021q$78n$1@z-news.wcss.wroc.pl> <9GUQI.8728$Bg6.71@fx42.iad>
<r1VQI.5573$xY.4985@fx05.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 11 Aug 2021 19:10:11 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ebac4182797cc3b1d63c47001b000224";
logging-data="3600"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1945qwYld4rImbtv22+FUgSFQuQI66kViw="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:fW5ka6dPI+ZfDl33/s0cpDsX7U0=
In-Reply-To: <r1VQI.5573$xY.4985@fx05.iad>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210811-2, 11/8/2021), Outbound message
 by: Bart - Wed, 11 Aug 2021 19:10 UTC

On 11/08/2021 19:54, Scott Lurndal wrote:
> DFS <nospam@dfs.com> writes:
>> On 8/11/2021 4:34 AM, antispam@math.uni.wroc.pl wrote:
>>
>>
>>> The 'strcat' in a loop is classic antipattern: it causes quadratic
>>> complexity to to repeated scanning for end of 'line'. Use something
>>> like
>>>
>>> char * cp = line;
>>> .....
>>> strcat(cp, buff);
>>> cp += strlen(buff);
>>> ....
>>>
>>
>> From other posts:
>>
>>> Bacarisse: "my favourite is cp += snprintf(cp, "%s", whatever);"
>>> (he meant to say sprintf)
>>
>>> Lurndal: "Building it with snprintf() will be far more flexible and
>>> efficient."
>>
>>
>>
>> build string, in seconds
>> ----------------------------- build +
>> antispam sprintf()/ print to
>> substring matches strcat as above snprintf() screen
>>
>> catt 91 0.036 0.036 0.036 0.037
>> cat 3710 0.067 0.038 0.038 0.129
>> ca 22793 1.423 0.044 0.052 0.657
>> c 128689 53.591 0.084 0.139 4.437
>> e 252896 207.782 0.132 0.238 8.598
>>
>>
>> Much better! Thanks for the suggestions.
>>
>>
>> built on Win10, using Mingw-w64 GCC
>> http://mingw-w64.org/doku.php
>>
>> which I got via
>> https://github.com/skeeto/w64devkit/releases/tag/v1.8.0
>>
>> run in cmd.exe shell inside ConEmu
>>
>> $ prog wordlist.txt option1234 (for dev and testing)
>>
>> ===========================================================================
>> //print matching words in columns of the same size, with no line
>> // wrapping in middle of word
>>
>> //array large enough to output 370K words of length 31
>> static char line[12000000];
>>
>> void showresults(char *matchwords[], int matchcnt, int stropt) {
>>
>
> I was thinking more along the lines of this:
>
> static char line[12000000];
>
> /**
> * Catenate the words from 'matchwords' into 'line', computing the
> * word length of the longest single word along the way.
> *
> * @param matchwords A vector of character pointers, one for each word
> * @param matchcnt The number of entries in the matchwords vector.
> */
> void
> showresults(char **matchwords, size_t matchcnt)
> {
> size_t longest_word = 0ul;
> char *lp = line;
> char *elp = &line[sizeof(line)];
>
> for(size_t i = 0ul; i < matchcount; i++) {
> char *cp = *matchwords++;
> size_t len = 0ul;
> while ((*cp != '\0') && (lp < elp)) {
> len++;
> *lp++ = *cp++;
> }
> longest_word = max(longest_word, len);
> }
>
> if (lp < elp) *lp++ = '\0';
> else line[sizeof(line)-1] = '\0';
>
> puts(line);
> }
>
> It will silently truncate the output string if 'line'
> isn't large enough to collect all the words in 'matchwords'.
>
> The implementation of max is left to the student.
>

Oh, I see you managed to make time for this, then!

I hadn't even asked you to write any code, just to look at my results.

I can take it then that my observations were on the mark since you
aren't interested in refuting them.

Re: Why does C allow structs to have a tag?

<4XVQI.40335$Fx8.28023@fx45.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!4.us.feeder.erje.net!3.eu.feeder.erje.net!feeder.erje.net!feeder5.feed.usenet.farm!feeder1.feed.usenet.farm!feed.usenet.farm!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx45.iad.POSTED!not-for-mail
Subject: Re: Why does C allow structs to have a tag?
Newsgroups: comp.lang.c
References: <s9iea5$n5c$1@dont-email.me> <seejf8$9ti$1@dont-email.me>
<WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me>
<CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me>
<87czqnlp2m.fsf@bsb.me.uk> <WFWPI.1865$un2.1665@fx04.iad>
<FiCQI.401$uk4.259@fx20.iad> <poCQI.37363$EF2.25668@fx47.iad>
<VNCQI.5685$Ug5.514@fx24.iad> <seuu75$il3$1@dont-email.me>
<TEEQI.5686$Ug5.143@fx24.iad> <GCQQI.17254$lK.16624@fx41.iad>
<5d8700fd-6ba7-4c72-ae2f-1d4ea91fe823n@googlegroups.com>
<PHRQI.5464$xY.2133@fx05.iad> <sf0re4$v91$1@dont-email.me>
From: nos...@dfs.com (DFS)
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
MIME-Version: 1.0
In-Reply-To: <sf0re4$v91$1@dont-email.me>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 8bit
Lines: 50
Message-ID: <4XVQI.40335$Fx8.28023@fx45.iad>
X-Complaints-To: abuse@blocknews.net
NNTP-Posting-Date: Wed, 11 Aug 2021 19:55:44 UTC
Organization: blocknews - www.blocknews.net
Date: Wed, 11 Aug 2021 15:55:44 -0400
X-Received-Bytes: 2487
 by: DFS - Wed, 11 Aug 2021 19:55 UTC

On 8/11/2021 11:47 AM, Bart wrote:

> Start with this:
>
>     char str[100];
>     char* s;
>
> Then a loop like this (all unoptimised code to stop it being optimised
> out of existence):
>
>   for (int i=0; i<10000000; ++i) {
>       strcpy(str,"one ");
>       strcat(str,"two ");
>       strcat(str,"three ");
>       strcat(str,"four ");
>       strcat(str,"five");
>   }
>   puts(str);
>
>
> took 1 second (on my Windows PC running tcc). If use sprintf():
>
>   for (int i=0; i<10000000; ++i) {
>       s=str;
>       s+=sprintf(s,"%s","one ");
>       s+=sprintf(s,"%s","two ");
>       s+=sprintf(s,"%s","three ");
>       s+=sprintf(s,"%s","four ");
>          sprintf(s,"%s","five");
>   }
>   puts(s);

Did you mean to leave off the s+= in the last line?

> then it takes 5.5 seconds. With snprintf() as you suggest, it takes 6.1
> seconds. I thought you said every cycle matters?

FWIW: also on Windows

compiled with tcc
strcat : 0.7s
sprintf: 6.3s

compiled with Mingw-w64 GCC
strcat : 0.4s
sprintf: 4.4s

Re: Why does C allow structs to have a tag?

<B3WQI.8822$cd2.1956@fx02.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.uzoreto.com!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx02.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Why does C allow structs to have a tag?
Newsgroups: comp.lang.c
References: <s9iea5$n5c$1@dont-email.me> <WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me> <CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me> <87czqnlp2m.fsf@bsb.me.uk> <WFWPI.1865$un2.1665@fx04.iad> <FiCQI.401$uk4.259@fx20.iad> <poCQI.37363$EF2.25668@fx47.iad> <VNCQI.5685$Ug5.514@fx24.iad> <seuu75$il3$1@dont-email.me> <TEEQI.5686$Ug5.143@fx24.iad> <sf021q$78n$1@z-news.wcss.wroc.pl> <9GUQI.8728$Bg6.71@fx42.iad> <r1VQI.5573$xY.4985@fx05.iad> <sf17aj$3gg$1@dont-email.me>
Lines: 8
Message-ID: <B3WQI.8822$cd2.1956@fx02.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 11 Aug 2021 20:04:49 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 11 Aug 2021 20:04:49 GMT
X-Received-Bytes: 1354
 by: Scott Lurndal - Wed, 11 Aug 2021 20:04 UTC

Bart <bc@freeuk.com> writes:
>On 11/08/2021 19:54, Scott Lurndal wrote:

>I can take it then that my observations were on the mark since you
>aren't interested in refuting them.
>

No, I'm just not interested in you and your silly obsessions.

Re: Why does C allow structs to have a tag?

<sf1bdc$pa9$1@z-news.wcss.wroc.pl>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!newsfeed.pionier.net.pl!pwr.wroc.pl!news.wcss.wroc.pl!not-for-mail
From: antis...@math.uni.wroc.pl
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Wed, 11 Aug 2021 20:19:56 +0000 (UTC)
Organization: Politechnika Wroclawska
Lines: 134
Message-ID: <sf1bdc$pa9$1@z-news.wcss.wroc.pl>
References: <s9iea5$n5c$1@dont-email.me> <WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me> <CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me> <87czqnlp2m.fsf@bsb.me.uk> <sepbrd$vg4$1@dont-email.me> <877dgvljpf.fsf@bsb.me.uk> <2a1b4347-595a-469a-8df1-db64af9896acn@googlegroups.com> <Wg_PI.6656$NQ1.5159@fx48.iad> <94f47c65-5f5f-44d1-bc37-d51155624ae5n@googlegroups.com> <sesbbk$63q$1@dont-email.me> <sf10rj$7g9$1@z-news.wcss.wroc.pl> <sf1712$t4a$1@dont-email.me>
NNTP-Posting-Host: hera.math.uni.wroc.pl
X-Trace: z-news.wcss.wroc.pl 1628713196 25929 156.17.86.1 (11 Aug 2021 20:19:56 GMT)
X-Complaints-To: abuse@news.pwr.wroc.pl
NNTP-Posting-Date: Wed, 11 Aug 2021 20:19:56 +0000 (UTC)
Cancel-Lock: sha1:OcfHlHWMpOE9Mx0BP/3Cpg6VGvQ=
User-Agent: tin/2.4.3-20181224 ("Glen Mhor") (UNIX) (Linux/4.19.0-10-amd64 (x86_64))
 by: antis...@math.uni.wroc.pl - Wed, 11 Aug 2021 20:19 UTC

Bart <bc@freeuk.com> wrote:
> On 11/08/2021 18:19, antispam@math.uni.wroc.pl wrote:
> > Bart <bc@freeuk.com> wrote:
>
> >> And when I have to play with C, I prefer my own small C compiler; you
> >> know, that one with the faster printf than gcc/tdm.
> >
> > I like small and fast programs. But here it looks like
> > you really want to mislead other folks.
>
> I gave timings for bcc, tcc, gcc**, clang**, CL, DMC and lccwin.
>
> There was a mixup over the ones marked ** which is explained below. But
> some gcc/clang versions were much slower. lccwin was in between.
>
>
> > First, what
> > you are measuring is speed of Windows console. IIUC
> > correctly what you wrote in your case Windows console
> > is fast enough: if you read printed text time spent
> > in console will be negligible compared to time spent
> > reading. And if console were too slow simple way
> > to solve problem is to get faster console: AFAICS
> > other folks pointed out that Microsoft provides
> > faster console and consoles from third party
> > (Cygwin and Msys) are faster too.
>
> That's not really relevant. All compilers were running the same program
> under the same OS and with the same, bog-standard MS Command Prompt.
>
> If one compiler exhibits much slower behaviour, then it's odd to suspect
> the console first.

Why odd. On my Linux machine running program that you
provided I get:

time ./b1
<lot of output>
1234567890 1234567890 1234567890 1234567890 1234567890
real 0m0.282s
user 0m0.012s
sys 0m0.000s

That says that program took 12ms CPU time to run, while real time
between start and finish is 282ms. It is odd to not notice that
most real time is spent _outside_ program. And the clear suspect
for causing bigger real time is console. AFAIK Windows has also
tools that allow you to see this.

And even if you have no tools it is rater easy to estimate time
spent in your program, and even 282ms that I see is much bigger
than any resonable estimate of runtime (and 3s that you reported
is really way off).

And simple way to isolate console effects is output to a file,
you know that this is much faster, so you really have no
excuse.

> > Second, any semi-decent tool to measure exection
> > time will tell you that time spent in your program
> > is negligible and basically 100% of time is
> > spent in Windows console. But instead of telling
> > that Windows console has a quirk which make it
> > much slower with one way of driving it (which
> > happen to be used by your gcc/tdm package) you
> > spin it as "gcc is slower than tcc".
>
> DFS has observed the effect; I have observed it. Other who haven't
> observed it haven't been using the same platform or the right compilers.

The point is what "the effect" is! If you mean execution
time of your program, then without any measurement I know
that it is negligile. If you measured, you will know to.
Or rather, you already know, but you prefer doing propaganda.

Put it differently: when you throw pathological program at
gcc and gcc takes long time to compile it, this is gcc problem.
When library bundled with your gcc install sends output to
window console that causes long execution time in console
that is gcc problem. When your compiler has trouble
with some code this is also gcc problem, without gcc
people would write simpler code that your compiler can
handle.

Note: I do not dispute your observations, but what they
mean.
> > Third, every programmer must understand importance
> > of being precise: programmer job is tell computer
> > what to do and if programer is not precise
> > enough computer will reject the task or do wrong
> > thing. Other explaned you difference between
> > gcc and package that you get. This distinction
> > matters because it tells you where to report
> > problem. In your case, if you honestly do
> > not know which part is responsible, then it
> > is resonable to report problems to whoever is
> > behind TDM project.
>
> If you look at my first post on the subject (8-8-21 15:41 BST) it was to
> confirm what DFS had observed, and I suggested a workaround.
>
> But everyone seems very keen to challenge what I'd said.

DFS can be excused as he apparently does not know what
happened. You know, but prefer misleading formulation.

> > OTOH, if you think that
> > problem is in core gcc, then it is resonable
> > to report it to gcc folks (since your version
> > is quite old you may get answer "fixed in
> > newer release", but that is another topic).
> > If you identify specific library or tool it
> > makes sense to report problem to authors
> > of problematic components.
>
> I really have no idea who's reponsible for what. And I don't care as
> it's not my product so not my headache.

If you do not care, then why so much fuss? Here you are responding
to DFS, but there were many threads started by you.

> (It's also, now, exhibited on two separate builds: gcc/tdm 10.3.0, from
> FSF Inc, and gcc 11.2.0 from chap called Brecht Sanders.)
>
> > Forth, you are jumping to conclusion: you do not
> > know why printf in your gcc/tdm package is doing
> > output in the specific way.
>
> No, I don't, but that's what it does.
>

--
Waldek Hebisch

Re: Why does C allow structs to have a tag?

<sf1d0q$iiu$1@dont-email.me>

  copy mid

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

  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: Why does C allow structs to have a tag?
Date: Wed, 11 Aug 2021 22:47:21 +0200
Organization: A noiseless patient Spider
Lines: 78
Message-ID: <sf1d0q$iiu$1@dont-email.me>
References: <s9iea5$n5c$1@dont-email.me> <seejf8$9ti$1@dont-email.me>
<WowPI.4743$NQ1.1007@fx48.iad> <sembba$oul$1@dont-email.me>
<CrQPI.669$bS5.239@fx21.iad> <seoqf4$pj7$1@dont-email.me>
<87czqnlp2m.fsf@bsb.me.uk> <WFWPI.1865$un2.1665@fx04.iad>
<FiCQI.401$uk4.259@fx20.iad> <poCQI.37363$EF2.25668@fx47.iad>
<VNCQI.5685$Ug5.514@fx24.iad> <seuu75$il3$1@dont-email.me>
<TEEQI.5686$Ug5.143@fx24.iad> <GCQQI.17254$lK.16624@fx41.iad>
<5d8700fd-6ba7-4c72-ae2f-1d4ea91fe823n@googlegroups.com>
<PHRQI.5464$xY.2133@fx05.iad> <sf0re4$v91$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 11 Aug 2021 20:47:22 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="e6cfd304f44f5e9d999e88ba65cdf961";
logging-data="19038"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19XoSjnc6qnCRkxcQfpIpipJ23JUllP7JE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:XNWN6Dw19AvWJIVsghBuhuxvzR0=
In-Reply-To: <sf0re4$v91$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Wed, 11 Aug 2021 20:47 UTC

On 11/08/2021 17:47, Bart wrote:
> On 11/08/2021 16:06, Scott Lurndal wrote:
>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>>> On Wednesday, 11 August 2021 at 14:52:54 UTC+1, Scott Lurndal wrote:
>>>>
>>>> strcat is almost never the right interface to use. It needs
>>>> to scan the entire string to find the terminal nul-byte before
>>>> appending. As the string gets longer, each strcat takes longer
>>>> than the one before.
>>>>
>>>> Just keep a pointer to the next element and increment the
>>>> pointer each time you add a new element.
>>>>
>>> Most strings are short. Building up a url with strcat is not going to
>>> stress a 3GHz machine. If the strings become huge then, yes, you
>>> need to look at more efficient ways of concatenating them.
>>
>> Building it with snprintf() will be far more flexible and efficient.
>>
>> Every cycle matters.
>>
>
>
> Start with this:
>
>     char str[100];
>     char* s;
>
> Then a loop like this (all unoptimised code to stop it being optimised
> out of existence):

As you well know, timing unoptimised code is an utterly pointless
exercise. You need to do something to make sure the operations are
carried out, such as judicious use of volatile, or using "global"
variables rather than local ones. Disabling optimisation is like
comparing the speed of cars while forcing them to remain in first gear.

>
>   for (int i=0; i<10000000; ++i) {
>       strcpy(str,"one ");
>       strcat(str,"two ");
>       strcat(str,"three ");
>       strcat(str,"four ");
>       strcat(str,"five");
>   }
>   puts(str);
>
>
> took 1 second (on my Windows PC running tcc). If use sprintf():
>
>   for (int i=0; i<10000000; ++i) {
>       s=str;
>       s+=sprintf(s,"%s","one ");
>       s+=sprintf(s,"%s","two ");
>       s+=sprintf(s,"%s","three ");
>       s+=sprintf(s,"%s","four ");
>          sprintf(s,"%s","five");
>   }
>   puts(s);
>
> then it takes 5.5 seconds. With snprintf() as you suggest, it takes 6.1
> seconds. I thought you said every cycle matters?
>

<https://godbolt.org/z/954eccfsM>

gcc (and I really mean gcc - no libraries are involved) generates
identical code in both cases, and so I would assume (without testing)
that the speed is the same.

> These all write into the same string. If each iteration uses a newly
> allocated 100-char string, then the strcat loop takes 2.2 seconds, and
> both forms of sprintf take something over 7 seconds.
>
> If I take the second loop above, and write the string directly (so not
> using "%s"), then it makes no difference; it's not the formatting that
> takes the extra time, not for %s anyway, it must be other overheads.

Pages:12345678910111213141516
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor