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


Groups > comp.lang.c > #388422

Re: Command line globber/tokenizer library for C?

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: Command line globber/tokenizer library for C?
Date 2024-09-17 03:12 -0700
Organization A noiseless patient Spider
Message-ID <86a5g6bnd7.fsf@linuxsc.com> (permalink)
References (12 earlier) <20240912223828.00005c10@yahoo.com> <861q1nfsjz.fsf@linuxsc.com> <20240915122211.000058b1@yahoo.com> <86y13savd1.fsf@linuxsc.com> <20240916122338.00000bae@yahoo.com>

Show all headers | View raw


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.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-10 19:01 +0000
  Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-10 20:58 +0000
    Re: Command line globber/tokenizer library for C? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-10 14:12 -0700
  Re: Command line globber/tokenizer library for C? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-10 23:05 +0200
    Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-10 22:11 +0000
  Re: Command line globber/tokenizer library for C? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-10 14:37 -0700
    Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-10 22:13 +0000
  Re: Command line globber/tokenizer library for C? gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-11 01:56 +0000
    Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-11 02:54 +0000
  Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-11 14:17 +0200
    Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-11 12:22 +0000
      Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-11 14:28 +0200
        Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-11 12:44 +0000
    Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-11 13:42 +0100
    Re: Command line globber/tokenizer library for C? gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-11 14:59 +0000
      Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-11 20:14 +0200
        Re: Command line globber/tokenizer library for C? gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-11 18:17 +0000
        Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-11 18:49 +0000
          Re: Command line globber/tokenizer library for C? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-11 14:43 -0700
            Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-12 03:06 +0000
              Re: Command line globber/tokenizer library for C? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-11 20:37 -0700
                Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-12 03:56 +0000
                Re: Command line globber/tokenizer library for C? gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-12 13:22 +0000
                Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-12 13:50 +0000
                Columbia (Was: Command line globber/tokenizer library for C?) gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-12 14:06 +0000
                Re: Columbia (Was: Command line globber/tokenizer library for C?) Michael S <already5chosen@yahoo.com> - 2024-09-12 17:20 +0300
                Re: Columbia (Was: Command line globber/tokenizer library for C?) David Brown <david.brown@hesbynett.no> - 2024-09-12 16:43 +0200
                Re: Columbia (Was: Command line globber/tokenizer library for C?) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-12 22:07 +0000
              Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-12 04:14 +0000
              Re: Command line globber/tokenizer library for C? Ben Bacarisse <ben@bsb.me.uk> - 2024-09-12 10:43 +0100
        Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-11 21:19 +0100
          Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 04:22 +0200
            Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-12 12:29 +0100
              Re: Command line globber/tokenizer library for C? gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-12 12:13 +0000
                Re: Command line globber/tokenizer library for C? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-12 14:24 +0200
                Other programming languages (Was: Command line globber/tokenizer library for C?) gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-12 13:20 +0000
                Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 16:01 +0200
                Re: Other programming languages (Was: Command line globber/tokenizer library for C?) gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-12 14:07 +0000
                Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 16:14 +0200
                Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-12 17:40 +0200
                Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 17:48 +0200
                Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-12 17:59 +0200
                Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-12 22:32 +0000
                Re: Other programming languages (Was: Command line globber/tokenizer library for C?) James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-09-12 18:50 -0400
                Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-13 01:37 +0000
                Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Michael S <already5chosen@yahoo.com> - 2024-09-13 11:30 +0300
                Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-13 04:06 +0200
                Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-13 02:58 +0000
                Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-13 14:31 +0200
                Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Kaz Kylheku <643-408-1753@kylheku.com> - 2024-09-13 04:18 +0000
                Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Kaz Kylheku <643-408-1753@kylheku.com> - 2024-09-13 03:38 +0000
                Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 16:00 +0200
              Re: Command line globber/tokenizer library for C? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-12 14:20 +0200
                Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-12 14:44 +0100
                Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-12 15:16 +0100
                Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 16:23 +0200
                Re: Command line globber/tokenizer library for C? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-12 17:46 +0200
                Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-12 17:15 +0100
                Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 18:26 +0200
                Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-12 18:16 +0300
                Re: Command line globber/tokenizer library for C? scott@slp53.sl.home (Scott Lurndal) - 2024-09-12 15:37 +0000
                Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-12 18:49 +0300
                Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-12 17:28 +0100
                Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 19:02 +0200
                Re: Command line globber/tokenizer library for C? gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-12 17:39 +0000
                Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-12 22:38 +0300
                Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-13 07:28 +0200
                Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-13 11:38 +0300
                Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-13 14:12 +0200
                Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-13 15:25 +0300
                Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-13 15:20 +0200
                Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-13 22:24 +0000
                Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-14 01:42 +0200
                Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-14 01:41 +0000
                Re: Command line globber/tokenizer library for C? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-13 09:05 -0700
                Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-15 12:22 +0300
                Re: Command line globber/tokenizer library for C? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-16 00:52 -0700
                Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-16 12:23 +0300
                Re: Command line globber/tokenizer library for C? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-17 03:12 -0700
                Re: Command line globber/tokenizer library for C? antispam@fricas.org - 2024-09-17 22:34 +0000
                Re: Command line globber/tokenizer library for C? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-17 16:33 -0700
                Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-18 02:46 +0300
                Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-18 01:07 +0100
                Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-18 11:43 +0300
                Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-18 10:49 +0100
                Re: Command line globber/tokenizer library for C? David Brown <david.brown@hesbynett.no> - 2024-09-18 12:44 +0200
                Re: Command line globber/tokenizer library for C? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-18 06:01 -0700
                Re: Command line globber/tokenizer library for C? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-17 18:31 -0700
                Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-18 11:03 +0300
                Re: Command line globber/tokenizer library for C? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-18 05:09 -0700
                Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-18 02:20 +0000
                Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-18 11:05 +0300
                Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 16:04 +0200
                Re: Command line globber/tokenizer library for C? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-12 17:30 +0200
                Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 17:47 +0200
                Re: Command line globber/tokenizer library for C? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-12 17:56 +0200
                Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 18:09 +0200
                Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-13 02:43 +0000
                Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-13 07:27 +0200
                Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-13 06:49 +0000
                Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-13 11:49 +0300
                Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-13 22:04 +0000
                Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-13 23:48 +0100
                Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-14 01:41 +0000
                Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-14 10:58 +0100
                Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-14 22:37 +0000
              Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 15:58 +0200
  Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 17:08 +0200
    More OT BS (Was: Command line globber/tokenizer library for C?) gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-12 15:23 +0000
      Re: More OT BS (Was: Command line globber/tokenizer library for C?) Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 17:24 +0200
    Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-12 22:09 +0000

csiph-web