Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <20240916122338.00000bae@yahoo.com>
Deutsch   English   Français   Italiano  
<20240916122338.00000bae@yahoo.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Michael S <already5chosen@yahoo.com>
Newsgroups: comp.lang.c
Subject: Re: Command line globber/tokenizer library for C?
Date: Mon, 16 Sep 2024 12:23:38 +0300
Organization: A noiseless patient Spider
Lines: 109
Message-ID: <20240916122338.00000bae@yahoo.com>
References: <lkbjchFebk9U1@mid.individual.net>
	<vbs1om$3jkch$1@raubtier-asyl.eternal-september.org>
	<vbsb94$1rsji$1@news.xmission.com>
	<vbsmlb$3o6n2$1@raubtier-asyl.eternal-september.org>
	<vbsu1d$3p7pp$1@dont-email.me>
	<vbtj88$1kpm$1@raubtier-asyl.eternal-september.org>
	<vbujak$733i$3@dont-email.me>
	<vbum9i$8h2o$1@dont-email.me>
	<vbur72$99cr$1@dont-email.me>
	<20240912181625.00006e68@yahoo.com>
	<vbv4ra$b0hv$2@dont-email.me>
	<vbv6r1$bhc9$1@raubtier-asyl.eternal-september.org>
	<20240912223828.00005c10@yahoo.com>
	<861q1nfsjz.fsf@linuxsc.com>
	<20240915122211.000058b1@yahoo.com>
	<86y13savd1.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 16 Sep 2024 11:23:14 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7b4ecf2c0b8427f1b1d344bec1b1bd8b";
	logging-data="2876279"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18o4BFDsEKr+yGM0H3AAFbinnO8Rg5XSS0="
Cancel-Lock: sha1:gkJEKh3H5YlQduMv9rBzPgZguFE=
X-Newsreader: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-w64-mingw32)
Bytes: 5038

On Mon, 16 Sep 2024 00:52:26 -0700
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:

> Michael S <already5chosen@yahoo.com> writes:
> 
> [comments reordered]
> 
> > Also, while formally the program is written in C,  by spirit it's
> > something else.  May be, Lisp.  
> 
> I would call it a functional style, but still C.  Not a C style
> as most people are used to seeing it, I grant you that.  I still
> think of it as C though.
> 
> 
> > Lisp compilers are known to be very good at tail call elimination.
> > C compilers also can do it, but not reliably.  In this particular
> > case I am afraid that common C compilers will implement it as
> > written, i.e. without turning recursion into iteration.  
> 
> I routinely use gcc and clang, and both are good at turning
> this kind of mutual recursion into iteration (-Os or higher,
> although clang was able to eliminate all the recursion at -O1).
> I agree the recursion elimination is not as reliable as one
> would like;  in practice though I find it quite usable.
> 
> 
> > Tested on godbolt.
> > gcc -O2 turns it into iteration starting from v.4.4
> > clang -O2 turns it into iteration starting from v.4.0  
> 
> Both as expected.
> 

So, only 15 years for gcc and only 7 years for clang.

> > Latest icc still does not turn it into iteration at least along one
> > code paths.  
> 
> That's disappointing, but good to know.
> 
> > Latest MSVC implements it as written, 100% recursion.  
> 
> I'm not surprised at all.  In my admittedly very limited experience,
> MSVC is garbage.
> 

For sort of code that is important to me, gcc, clang and MSVC tend to
generate code of similar quality. clang is most suspect of the three to
sometimes unexpectedly produce utter crap. On the other hand, it is
sometimes most brilliant.
In case of gcc, I hate that recently they put tree-slp-vectorize under
-O2 umbrella.

> 
> > Can you give an example implementation of go->f() ?
> > It seems to me that it would have to use CONTAINING_RECORD or
> > container_of or analogous non-standard macro.  
> 
> You say that like you think such macros don't have well-defined
> behavior.  If I needed such a macro probably I would just
> define it myself (and would be confident that it would
> work correctly).
> 
> In this case I don't need a macro because I would put the gopher
> struct at the beginning of the containing struct.  For example:
> 
> #include <stdio.h>
> 
> typedef struct {
>     struct gopher_s go;
>     unsigned words;
> } WordCounter;
> 
> 
> static void
> print_word( Gopher go, const char *s, const char *t ){
>   WordCounter *context = (void*) go;

That's what I was missing. Simple and adequate.

>   int    n      =  t-s;
> 
>     printf( "  word:  %.*s\n", n, s );
>     context->words ++;
> }
> 

> 
> int
> main(){
>   WordCounter wc = { { print_word }, 0 };
>   char  *words = "\tthe quick \"brown fox\" jumps over the lazy dog.";
> 
>     words_do( words, &wc.go );
>     printf( "\n" );
>     printf( " There were %u words found\n", wc.words );
>     return  0;
> }

There are couple of differences between your and my parsing.
1. "42""43" 
You parse it as a single word, I split. It seems, your behavior is
closer to that of both bash and cmd.exe
2. I strip " characters from "-delimited words. You seem to leave them.
In this case what I do is more similar to both bash and cmd.exe

Not that it matters.