Re: Command line globber/tokenizer library for C?

Liste des GroupesRevenir à cl c 
Sujet : Re: Command line globber/tokenizer library for C?
De : tr.17687 (at) *nospam* z991.linuxsc.com (Tim Rentsch)
Groupes : comp.lang.c
Date : 17. Sep 2024, 12:12:04
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <86a5g6bnd7.fsf@linuxsc.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
User-Agent : Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Michael S <already5chosen@yahoo.com> writes:

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

To clarify, my earlier comment about MSVC is about what it thinks
the language is, not anything about quality of generated code.  But
the lack of tail call elimination fits in with what else I have
seen.

clang is most suspect of the three to sometimes unexpectedly
produce utter crap.  On the other hand, it is sometimes most
brilliant.

That's interesting.  Recently I encountered a problem where clang
did just fine but gcc generated bad code under -O3.

In case of gcc, I hate that recently they put tree-slp-vectorize
under -O2 umbrella.

Yes, gcc is like a box of chocolates - you never know what you're
going to get.

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.

I now prefer this technique for callbacks.  Cuts down on the
number of parameters, safer than a (void*) parameter, and it puts
the function pointer near the context state so it's easier to
connect the two (and less worry about them getting out of sync).

  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

Yes.  I chose that deliberately because I often use patterns like
foo."$suffix" and it made sense to allow quoted subparts for that
reason.

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

I do, both because it's easier, and in case the caller wants to
know where the quotes are.  If it's important to strip them out
it's up to the caller to do that.

Not that it matters.

Yeah.  These choices are only minor details;  the general
approach taken is the main thing.

Date Sujet#  Auteur
10 Sep 24 * Command line globber/tokenizer library for C?110ted@loft.tnolan.com (Ted Nolan
10 Sep 24 +* Re: Command line globber/tokenizer library for C?2Lawrence D'Oliveiro
10 Sep 24 i`- Re: Command line globber/tokenizer library for C?1Keith Thompson
10 Sep 24 +* Re: Command line globber/tokenizer library for C?2Janis Papanagnou
11 Sep 24 i`- Re: Command line globber/tokenizer library for C?1ted@loft.tnolan.com (Ted Nolan
10 Sep 24 +* Re: Command line globber/tokenizer library for C?2Keith Thompson
11 Sep 24 i`- Re: Command line globber/tokenizer library for C?1ted@loft.tnolan.com (Ted Nolan
11 Sep 24 +* Re: Command line globber/tokenizer library for C?2Kenny McCormack
11 Sep 24 i`- Re: Command line globber/tokenizer library for C?1ted@loft.tnolan.com (Ted Nolan
11 Sep 24 +* Re: Command line globber/tokenizer library for C?97Bonita Montero
11 Sep 24 i+* Re: Command line globber/tokenizer library for C?3ted@loft.tnolan.com (Ted Nolan
11 Sep 24 ii`* Re: Command line globber/tokenizer library for C?2Bonita Montero
11 Sep 24 ii `- Re: Command line globber/tokenizer library for C?1ted@loft.tnolan.com (Ted Nolan
11 Sep 24 i+- Re: Command line globber/tokenizer library for C?1Bart
11 Sep 24 i`* Re: Command line globber/tokenizer library for C?92Kenny McCormack
11 Sep 24 i `* Re: Command line globber/tokenizer library for C?91Bonita Montero
11 Sep 24 i  +- Re: Command line globber/tokenizer library for C?1Kenny McCormack
11 Sep 24 i  +* Re: Command line globber/tokenizer library for C?13ted@loft.tnolan.com (Ted Nolan
11 Sep 24 i  i`* Re: Command line globber/tokenizer library for C?12Keith Thompson
12 Sep 24 i  i `* Re: Command line globber/tokenizer library for C?11ted@loft.tnolan.com (Ted Nolan
12 Sep 24 i  i  +* Re: Command line globber/tokenizer library for C?8Keith Thompson
12 Sep 24 i  i  i`* Re: Command line globber/tokenizer library for C?7ted@loft.tnolan.com (Ted Nolan
12 Sep 24 i  i  i `* Re: Command line globber/tokenizer library for C?6Kenny McCormack
12 Sep 24 i  i  i  `* Re: Command line globber/tokenizer library for C?5ted@loft.tnolan.com (Ted Nolan
12 Sep 24 i  i  i   `* Columbia (Was: Command line globber/tokenizer library for C?)4Kenny McCormack
12 Sep 24 i  i  i    `* Re: Columbia (Was: Command line globber/tokenizer library for C?)3Michael S
12 Sep 24 i  i  i     +- Re: Columbia (Was: Command line globber/tokenizer library for C?)1David Brown
13 Sep 24 i  i  i     `- Re: Columbia (Was: Command line globber/tokenizer library for C?)1Lawrence D'Oliveiro
12 Sep 24 i  i  +- Re: Command line globber/tokenizer library for C?1Lawrence D'Oliveiro
12 Sep 24 i  i  `- Re: Command line globber/tokenizer library for C?1Ben Bacarisse
11 Sep 24 i  `* Re: Command line globber/tokenizer library for C?76Bart
12 Sep 24 i   `* Re: Command line globber/tokenizer library for C?75Bonita Montero
12 Sep 24 i    `* Re: Command line globber/tokenizer library for C?74Bart
12 Sep 24 i     +* Re: Command line globber/tokenizer library for C?19Kenny McCormack
12 Sep 24 i     i+* Re: Command line globber/tokenizer library for C?17Janis Papanagnou
12 Sep 24 i     ii`* Other programming languages (Was: Command line globber/tokenizer library for C?)16Kenny McCormack
12 Sep 24 i     ii `* Re: Other programming languages (Was: Command line globber/tokenizer library for C?)15Bonita Montero
12 Sep 24 i     ii  `* Re: Other programming languages (Was: Command line globber/tokenizer library for C?)14Kenny McCormack
12 Sep 24 i     ii   `* Re: Other programming languages (Was: Command line globber/tokenizer library for C?)13Bonita Montero
12 Sep 24 i     ii    `* Re: Other programming languages (Was: Command line globber/tokenizer library for C?)12Janis Papanagnou
12 Sep 24 i     ii     +* Re: Other programming languages (Was: Command line globber/tokenizer library for C?)2Bonita Montero
12 Sep 24 i     ii     i`- Re: Other programming languages (Was: Command line globber/tokenizer library for C?)1Janis Papanagnou
13 Sep 24 i     ii     `* Re: Other programming languages (Was: Command line globber/tokenizer library for C?)9Lawrence D'Oliveiro
13 Sep 24 i     ii      +* Re: Other programming languages (Was: Command line globber/tokenizer library for C?)3James Kuyper
13 Sep 24 i     ii      i`* Re: Other programming languages (Was: Command line globber/tokenizer library for C?)2Lawrence D'Oliveiro
13 Sep 24 i     ii      i `- Re: Other programming languages (Was: Command line globber/tokenizer library for C?)1Michael S
13 Sep 24 i     ii      +* Re: Other programming languages (Was: Command line globber/tokenizer library for C?)4Janis Papanagnou
13 Sep 24 i     ii      i+* Re: Other programming languages (Was: Command line globber/tokenizer library for C?)2Lawrence D'Oliveiro
13 Sep 24 i     ii      ii`- Re: Other programming languages (Was: Command line globber/tokenizer library for C?)1Janis Papanagnou
13 Sep 24 i     ii      i`- Re: Other programming languages (Was: Command line globber/tokenizer library for C?)1Kaz Kylheku
13 Sep 24 i     ii      `- Re: Other programming languages (Was: Command line globber/tokenizer library for C?)1Kaz Kylheku
12 Sep 24 i     i`- Re: Command line globber/tokenizer library for C?1Bonita Montero
12 Sep 24 i     +* Re: Command line globber/tokenizer library for C?53Janis Papanagnou
12 Sep 24 i     i+* Re: Command line globber/tokenizer library for C?38Bart
12 Sep 24 i     ii+* Re: Command line globber/tokenizer library for C?5Bart
12 Sep 24 i     iii+- Re: Command line globber/tokenizer library for C?1Bonita Montero
12 Sep 24 i     iii`* Re: Command line globber/tokenizer library for C?3Janis Papanagnou
12 Sep 24 i     iii `* Re: Command line globber/tokenizer library for C?2Bart
12 Sep 24 i     iii  `- Re: Command line globber/tokenizer library for C?1Bonita Montero
12 Sep 24 i     ii`* Re: Command line globber/tokenizer library for C?32Michael S
12 Sep 24 i     ii +- Re: Command line globber/tokenizer library for C?1Michael S
12 Sep 24 i     ii `* Re: Command line globber/tokenizer library for C?30Bart
12 Sep 24 i     ii  `* Re: Command line globber/tokenizer library for C?29Bonita Montero
12 Sep 24 i     ii   +- Re: Command line globber/tokenizer library for C?1Kenny McCormack
12 Sep 24 i     ii   `* Re: Command line globber/tokenizer library for C?27Michael S
13 Sep 24 i     ii    +* Re: Command line globber/tokenizer library for C?8Bonita Montero
13 Sep 24 i     ii    i`* Re: Command line globber/tokenizer library for C?7Michael S
13 Sep 24 i     ii    i `* Re: Command line globber/tokenizer library for C?6Bonita Montero
13 Sep 24 i     ii    i  +* Re: Command line globber/tokenizer library for C?2Michael S
13 Sep 24 i     ii    i  i`- Re: Command line globber/tokenizer library for C?1Bonita Montero
14 Sep 24 i     ii    i  `* Re: Command line globber/tokenizer library for C?3Lawrence D'Oliveiro
14 Sep 24 i     ii    i   `* Re: Command line globber/tokenizer library for C?2Bonita Montero
14 Sep 24 i     ii    i    `- Re: Command line globber/tokenizer library for C?1Lawrence D'Oliveiro
13 Sep 24 i     ii    `* Re: Command line globber/tokenizer library for C?18Tim Rentsch
15 Sep11:22 i     ii     `* Re: Command line globber/tokenizer library for C?17Michael S
16 Sep09:52 i     ii      +* Re: Command line globber/tokenizer library for C?3Tim Rentsch
16 Sep11:23 i     ii      i`* Re: Command line globber/tokenizer library for C?2Michael S
17 Sep12:12 i     ii      i `- Re: Command line globber/tokenizer library for C?1Tim Rentsch
18 Sep00:34 i     ii      `* Re: Command line globber/tokenizer library for C?13antispam
18 Sep01:33 i     ii       +- Re: Command line globber/tokenizer library for C?1Tim Rentsch
18 Sep01:46 i     ii       `* Re: Command line globber/tokenizer library for C?11Michael S
18 Sep02:07 i     ii        +* Re: Command line globber/tokenizer library for C?5Bart
18 Sep10:43 i     ii        i`* Re: Command line globber/tokenizer library for C?4Michael S
18 Sep11:49 i     ii        i +* Re: Command line globber/tokenizer library for C?2Bart
18 Sep12:44 i     ii        i i`- Re: Command line globber/tokenizer library for C?1David Brown
18 Sep15:01 i     ii        i `- Re: Command line globber/tokenizer library for C?1Tim Rentsch
18 Sep03:31 i     ii        +* Re: Command line globber/tokenizer library for C?3Tim Rentsch
18 Sep10:03 i     ii        i`* Re: Command line globber/tokenizer library for C?2Michael S
18 Sep14:09 i     ii        i `- Re: Command line globber/tokenizer library for C?1Tim Rentsch
18 Sep04:20 i     ii        `* Re: Command line globber/tokenizer library for C?2Lawrence D'Oliveiro
18 Sep10:05 i     ii         `- Re: Command line globber/tokenizer library for C?1Michael S
12 Sep 24 i     i`* Re: Command line globber/tokenizer library for C?14Bonita Montero
12 Sep 24 i     i `* Re: Command line globber/tokenizer library for C?13Janis Papanagnou
12 Sep 24 i     i  `* Re: Command line globber/tokenizer library for C?12Bonita Montero
12 Sep 24 i     i   +* Re: Command line globber/tokenizer library for C?2Janis Papanagnou
12 Sep 24 i     i   i`- Re: Command line globber/tokenizer library for C?1Bonita Montero
13 Sep 24 i     i   `* Re: Command line globber/tokenizer library for C?9Lawrence D'Oliveiro
13 Sep 24 i     i    `* Re: Command line globber/tokenizer library for C?8Bonita Montero
13 Sep 24 i     i     `* Re: Command line globber/tokenizer library for C?7Lawrence D'Oliveiro
13 Sep 24 i     i      `* Re: Command line globber/tokenizer library for C?6Michael S
14 Sep 24 i     i       `* Re: Command line globber/tokenizer library for C?5Lawrence D'Oliveiro
12 Sep 24 i     `- Re: Command line globber/tokenizer library for C?1Bonita Montero
12 Sep 24 `* Re: Command line globber/tokenizer library for C?4Bonita Montero

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal