Re: Suggested method for returning a string from a C program?

Liste des GroupesRevenir à cl c 
Sujet : Re: Suggested method for returning a string from a C program?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.c
Date : 22. Mar 2025, 04:50:51
Autres entêtes
Organisation : None to speak of
Message-ID : <87cye9afl0.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
User-Agent : Gnus/5.13 (Gnus v5.13)
bart <bc@freeuk.com> writes:
On 21/03/2025 19:04, Keith Thompson wrote:
bart <bc@freeuk.com> writes:
On 21/03/2025 01:47, Keith Thompson wrote:
bart <bc@freeuk.com> writes:
You're complaining about how much work it is.  All that work
has been done for you by the implementers.  Decades ago.
>
We are talking about defining types like 'int32' on top of 'char short
int long', yes? Then how difficult could it possibly be?
If you want <stdint.h> and <inttypes.h> headers that work correctly
with all relevant compilers, it's not particularly easy.  I'll note
that the MUSL implementation of <stdint.h> is 117 lines, compared to
308 for GNU libc.
 
I just did a quick test comparing complation times for an empty
program with no #include directives and an empty program with
#include directives for <stdint.h> and <inttypes.h>.  The
difference was about 3 milliseconds.  I quite literally could not
care care less.
>
I'm sorry but that's a really poor attitude, with bad
consequences. You're saying it doesn't matter how complex a header or
set of headers is, even when out of proportion to the task.
>
But this is why we end up with such complicated headers.
Complicated headers that work.
[...\
 
I think your response clarifies matters. Nobody cares, even as
compilers grind to a halt under all preprocessing.
If compilers ground to a halt, I would certainly care.  They don't.
>
50 modules each including GTK.h say, which was 0.33Mloc across 500
headers (so reading 16Mloc and 25,000 headers in total when all are
compiled) would not impact your builds at all? OK.

First you talked about compilers grinding to a halt, then you talked
about headers not impacting builds at all.  Those goalposts of yours
move *fast*.

For the record, as you can see above, I did not say that builds would
not be impacted.  Do not put words into my mouth again.

But I expect if a major library supplier came out with the idea of a
streamlined, compact one-file header that took 90% less compile-time,
that would be hailed as a brilliant advance!
>
Doing stuff the C way requires LOTs of lines of code. Look at all
those MIN/MAX macros, the PRINT/SCAN macros; there's hundreds of them!
So what?  I don't have to read those lines of code.  All I have to
read
is the standard (or some other document) that tells me how to use it.
>
It is crass. But it also affects the programmer because they have to
explicitly include that specific header and then remember the
dedicated MIN/MAX macros for the specific type. And they have to
/know/ the type.
Yes, of course.
 
If the type is opaque, or is an alias, then they won't know the name
of the macro. If the typedef is 'T' for example, then what's the macro
for its MAX value? Which header will they need?
There may not be one.  For example, there's no format specifier for
time_t.  If I need to print a time_t value, I'll probably cast to
intmax_t and use "%jd".  If I'm being obsessive about portability, I'll
test whether time_t is signed, unsigned, or floating-point (all of which
are possible in principle), and use "%jd", "%ju", or "%Lf".
>
I wonder if you realise how utterly ridiculous all those incantations sound?

That's a matter of opinion.  I see your point, but they're not nearly as
ridiculous to someone who knows the language or who isn't looking for
things to complain about.

This is a C program using one of the extensions from my old compiler:
>
  #include <stdio.h>
  #include <time.h>
>
  int main(void) {
      time_t t = clock();
      printf("%v\n", t);             # (used to be '?'; changed to 'v')
  }
>
The compiler replaces the 'v' format with a conventional format code
according to the type of the expression. For my 'time_t', it happens
to be 'lld'.

That's nice.  Seriously, it's nice.  If it were added to a future
edition of the language, I'd likely use it (once I could count on it
being supported, which would take a while).

The Go language has something like that.

You can add extensions like that to your own compiler easily
enough.  Adding them to the C standard (which requires getting all
implementers to support them) is a lot harder.  Does it work for
both output (printf) and input (scanf)?  What if the format string
isn't a string literal; does the compiler generate code to adjust
it, allocating space for the translated string and deallocating it
after the call?  Does it work with printf("%n", &var)?  What about
qualifiers, specifying width, base, and so forth.  How do I print
an integer of arbitrary type in hexadecimal in a right-justified
8-digit zero-padded field?  The feature implies an ability for
generic code that works with different types; can programmers use
that feature for things other than format strings?  How much more
complicated would the C language (as distinct from the library)
have to be to support this?

If you have answers to all those questions, and to all the other
questions that haven't occurred to me, I wouldn't mind seeing
something like that in a future version of C.  I haven't looked
closely at Go, but it's a compiled language with a feature similar
to what you describe; it could probably be mined for ideas.

Or maybe we should be thinking in terms of something other than format
strings.  The idea that "%v", which is a 3-byte chunk of data, has
compile-time implications in certain contexts is a bit unnerving.

Ada chose the short name "Put" for its output routines.
It's overloaded, so you can write `Put(this); Put(that);
Put(the_other);` Maybe that a little too verbose, but how about
a new built-in operator that takes an argument of any of various
types and yields something that can be printed?  '$' is available.
I haven't thought this through.

Oh, sorry, did I violate your assumption that all I do is attack your
ideas?  (Disclaimer: I'm not sure you've said that in those words.)

In a certain language I use, it will be T.max (and there are no
headers). I'm not suggesting that C turns into that language, only
that somebody acknowledges the downsides of using C's approach, since
again nobody cares.
I acknowledge the downsides of C's approach.  See, all you had to
do was ask.
As Dennis Ritchie said, "C is quirky, flawed, and an enormous
success".
>
So it's quirky and flawed.

Yes, and an enormous success.

It would be very nice if C had some kind of more generic I/O that
doesn't require remembering arbitrary format strings and qualifiers
for each type, and that doesn't provide format strings for a lot of
types in the standard library, and certainly not for types defined
in user code.  And I'd *love* it if a future C standard removed
the undefined behavior for numeric input using *scanf().  Other C
programmers will have different priorities than yours or mine.
If I want to print a time_t value in C++, I just write
`std::cout << t` and the compiler figures out which overloaded
function to call.
>
That's amazing.

Not particularly.  C has programmer-defined operator (and function)
overloading as a language feature.  (There are IMHO some serious
flaws in C++'s use of overloaded "<<" for output, but I won't go
into that here.)

[...]

When I talk about how to work with C as it's currently defined,
you tend to see advocacy where it doesn't exist.  When you complain
about things in C that I don't think are real problems, you tend
to assume that I'm saying C is perfect, something I've never said.
When you ask why something in C is defined the way it is, you don't
acknowledge when people take the time to explain it.
>
This forum tends to not be critical of the language. But even if
aspects of it can't be changed, there's no reason not to call them
out.

This forum is full of people who are already aware of C's flaws.
Perhaps that's a reason not to call them out again and again
and again.  And perhaps there are more interesting criticisms than
"PRId64 is ugly".

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Date Sujet#  Auteur
19 Mar 25 * Suggested method for returning a string from a C program?401DFS
19 Mar 25 +* Re: Suggested method for returning a string from a C program?4Keith Thompson
19 Mar 25 i+- Re: Suggested method for returning a string from a C program?1Keith Thompson
19 Mar 25 i`* Re: Suggested method for returning a string from a C program?2DFS
19 Mar 25 i `- Re: Suggested method for returning a string from a C program?1Keith Thompson
19 Mar 25 +* Re: Suggested method for returning a string from a C program?333Tim Rentsch
19 Mar 25 i+* Re: Suggested method for returning a string from a C program?2DFS
19 Mar 25 ii`- Re: Suggested method for returning a string from a C program?1Richard Heathfield
19 Mar 25 i`* Re: Suggested method for returning a string from a C program?330DFS
19 Mar 25 i +* Re: Suggested method for returning a string from a C program?6Tim Rentsch
19 Mar 25 i i`* Re: Suggested method for returning a string from a C program?5DFS
19 Mar 25 i i +* Re: Suggested method for returning a string from a C program?3James Kuyper
19 Mar 25 i i i+- Re: Suggested method for returning a string from a C program?1Keith Thompson
19 Mar 25 i i i`- Re: Suggested method for returning a string from a C program?1DFS
19 Mar 25 i i `- Re: Suggested method for returning a string from a C program?1Tim Rentsch
19 Mar 25 i `* Re: Suggested method for returning a string from a C program?323Michael S
19 Mar 25 i  +* Re: Suggested method for returning a string from a C program?319DFS
19 Mar 25 i  i`* Re: Suggested method for returning a string from a C program?318Richard Heathfield
19 Mar 25 i  i `* Re: Suggested method for returning a string from a C program?317Michael S
19 Mar 25 i  i  +- Re: Suggested method for returning a string from a C program?1Richard Heathfield
20 Mar 25 i  i  `* Re: Suggested method for returning a string from a C program?315Tim Rentsch
20 Mar 25 i  i   `* Re: Suggested method for returning a string from a C program?314bart
20 Mar 25 i  i    +* Re: Suggested method for returning a string from a C program?308bart
20 Mar 25 i  i    i+* Re: Suggested method for returning a string from a C program?92Muttley
20 Mar 25 i  i    ii+* Re: Suggested method for returning a string from a C program?8Michael S
20 Mar 25 i  i    iii`* Re: Suggested method for returning a string from a C program?7Muttley
20 Mar 25 i  i    iii `* Re: Suggested method for returning a string from a C program?6Michael S
20 Mar 25 i  i    iii  +* Re: Suggested method for returning a string from a C program?3Muttley
23 Mar 25 i  i    iii  i`* Re: Suggested method for returning a string from a C program?2Michael S
23 Mar 25 i  i    iii  i `- Re: Suggested method for returning a string from a C program?1Tim Rentsch
20 Mar 25 i  i    iii  +- Re: Suggested method for returning a string from a C program?1Tim Rentsch
20 Mar 25 i  i    iii  `- Re: Suggested method for returning a string from a C program?1Keith Thompson
20 Mar 25 i  i    ii`* Re: Suggested method for returning a string from a C program?83bart
20 Mar 25 i  i    ii +- Re: Suggested method for returning a string from a C program?1Muttley
20 Mar 25 i  i    ii +* Re: Suggested method for returning a string from a C program?80Michael S
20 Mar 25 i  i    ii i`* Re: Suggested method for returning a string from a C program?79bart
20 Mar 25 i  i    ii i +* Re: Suggested method for returning a string from a C program?3Kaz Kylheku
20 Mar 25 i  i    ii i i`* Re: Suggested method for returning a string from a C program?2Michael S
20 Mar 25 i  i    ii i i `- Re: Suggested method for returning a string from a C program?1Kaz Kylheku
21 Mar 25 i  i    ii i `* Re: Suggested method for returning a string from a C program?75Keith Thompson
24 Mar 25 i  i    ii i  `* The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)74Janis Papanagnou
24 Mar 25 i  i    ii i   `* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)73Keith Thompson
25 Mar 25 i  i    ii i    `* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)72David Brown
25 Mar 25 i  i    ii i     +* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)5Kaz Kylheku
25 Mar 25 i  i    ii i     i`* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)4David Brown
25 Mar 25 i  i    ii i     i `* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)3Keith Thompson
26 Mar 25 i  i    ii i     i  +- Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)1Chris M. Thomasson
26 Mar 25 i  i    ii i     i  `- Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)1David Brown
25 Mar 25 i  i    ii i     +* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)64Janis Papanagnou
25 Mar 25 i  i    ii i     i+* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)54bart
25 Mar 25 i  i    ii i     ii`* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)53Janis Papanagnou
26 Mar 25 i  i    ii i     ii +* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)2bart
26 Mar 25 i  i    ii i     ii i`- Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)1Janis Papanagnou
26 Mar 25 i  i    ii i     ii `* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)50David Brown
26 Mar 25 i  i    ii i     ii  `* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)49Janis Papanagnou
26 Mar 25 i  i    ii i     ii   `* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)48David Brown
26 Mar 25 i  i    ii i     ii    `* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)47Janis Papanagnou
26 Mar 25 i  i    ii i     ii     +- Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)1David Brown
27 Mar 25 i  i    ii i     ii     `* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)45bart
27 Mar 25 i  i    ii i     ii      +- Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)1bart
27 Mar 25 i  i    ii i     ii      +* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)4Waldek Hebisch
27 Mar 25 i  i    ii i     ii      i`* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)3bart
27 Mar 25 i  i    ii i     ii      i +- Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)1David Brown
28 Mar 25 i  i    ii i     ii      i `- Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)1Waldek Hebisch
27 Mar 25 i  i    ii i     ii      `* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)39Janis Papanagnou
27 Mar 25 i  i    ii i     ii       +* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)13bart
28 Mar 25 i  i    ii i     ii       i`* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)12Janis Papanagnou
28 Mar 25 i  i    ii i     ii       i +* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)9David Brown
28 Mar 25 i  i    ii i     ii       i i+* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)7Janis Papanagnou
28 Mar 25 i  i    ii i     ii       i ii+* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)2Michael S
28 Mar 25 i  i    ii i     ii       i iii`- Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)1Janis Papanagnou
28 Mar 25 i  i    ii i     ii       i ii+* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)2bart
28 Mar 25 i  i    ii i     ii       i iii`- Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)1Janis Papanagnou
28 Mar 25 i  i    ii i     ii       i ii`* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)2David Brown
28 Mar 25 i  i    ii i     ii       i ii `- Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)1Janis Papanagnou
28 Mar 25 i  i    ii i     ii       i i`- Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)1Chris M. Thomasson
28 Mar 25 i  i    ii i     ii       i +- Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)1bart
31 Mar 25 i  i    ii i     ii       i `- [OT] PC hardware prices [correction] (was Re: The integral type 'byte')1Janis Papanagnou
27 Mar 25 i  i    ii i     ii       `* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)25David Brown
28 Mar 25 i  i    ii i     ii        `* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)24Janis Papanagnou
28 Mar 25 i  i    ii i     ii         +* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)18Chris M. Thomasson
28 Mar 25 i  i    ii i     ii         i`* [OT] SPARC (was Re: The integral type 'byte')17Janis Papanagnou
28 Mar 25 i  i    ii i     ii         i +- Re: [OT] SPARC (was Re: The integral type 'byte')1Keith Thompson
28 Mar 25 i  i    ii i     ii         i +* Re: [OT] SPARC (was Re: The integral type 'byte')14Michael S
28 Mar 25 i  i    ii i     ii         i i+* Re: [OT] SPARC (was Re: The integral type 'byte')8David Brown
28 Mar 25 i  i    ii i     ii         i ii+* Re: [OT] SPARC (was Re: The integral type 'byte')6Michael S
28 Mar 25 i  i    ii i     ii         i iii`* Re: [OT] SPARC (was Re: The integral type 'byte')5David Brown
28 Mar 25 i  i    ii i     ii         i iii +* Re: [OT] SPARC (was Re: The integral type 'byte')3Chris M. Thomasson
28 Mar 25 i  i    ii i     ii         i iii i+- Re: [OT] SPARC (was Re: The integral type 'byte')1Chris M. Thomasson
28 Mar 25 i  i    ii i     ii         i iii i`- Re: [OT] SPARC (was Re: The integral type 'byte')1Kaz Kylheku
28 Mar 25 i  i    ii i     ii         i iii `- Re: [OT] SPARC (was Re: The integral type 'byte')1Kaz Kylheku
28 Mar 25 i  i    ii i     ii         i ii`- Re: [OT] SPARC (was Re: The integral type 'byte')1Kaz Kylheku
28 Mar 25 i  i    ii i     ii         i i`* Re: [OT] SPARC (was Re: The integral type 'byte')5Janis Papanagnou
28 Mar 25 i  i    ii i     ii         i i `* Re: [OT] SPARC (was Re: The integral type 'byte')4Michael S
28 Mar 25 i  i    ii i     ii         i i  +* Re: [OT] SPARC (was Re: The integral type 'byte')2Janis Papanagnou
28 Mar 25 i  i    ii i     ii         i i  i`- Re: [OT] SPARC (was Re: The integral type 'byte')1David Brown
28 Mar 25 i  i    ii i     ii         i i  `- Re: [OT] SPARC (was Re: The integral type 'byte')1Kaz Kylheku
28 Mar 25 i  i    ii i     ii         i `- Re: [OT] SPARC (was Re: The integral type 'byte')1Chris M. Thomasson
28 Mar 25 i  i    ii i     ii         `* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)5David Brown
28 Mar 25 i  i    ii i     ii          +- Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)1Michael S
28 Mar 25 i  i    ii i     ii          +* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)2bart
28 Mar 25 i  i    ii i     ii          `- Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)1Janis Papanagnou
26 Mar 25 i  i    ii i     i`* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)9David Brown
25 Mar 25 i  i    ii i     `* Re: The integral type 'byte' (was Re: Suggested method for returning a string from a C program?)2Keith Thompson
20 Mar 25 i  i    ii `- Re: Suggested method for returning a string from a C program?1Keith Thompson
20 Mar 25 i  i    i+* Re: Suggested method for returning a string from a C program?103bart
20 Mar 25 i  i    i+* Re: Suggested method for returning a string from a C program?90Keith Thompson
21 Mar 25 i  i    i`* Re: Suggested method for returning a string from a C program?22Waldek Hebisch
20 Mar 25 i  i    +- Re: Suggested method for returning a string from a C program?1Michael S
20 Mar 25 i  i    +- Re: Suggested method for returning a string from a C program?1Muttley
20 Mar 25 i  i    +- Re: Suggested method for returning a string from a C program?1Kaz Kylheku
20 Mar 25 i  i    +- Re: Suggested method for returning a string from a C program?1Tim Rentsch
20 Mar 25 i  i    `- Re: Suggested method for returning a string from a C program?1Keith Thompson
19 Mar 25 i  `* Re: Suggested method for returning a string from a C program?3Tim Rentsch
19 Mar 25 +* Re: Suggested method for returning a string from a C program?27Keith Thompson
19 Mar 25 +* Re: Suggested method for returning a string from a C program?9Ike Naar
19 Mar 25 +* Re: Suggested method for returning a string from a C program?19bart
19 Mar 25 +* Re: Suggested method for returning a string from a C program?6Michael S
22 Mar 25 `* Re: Suggested method for returning a string from a C program?2Lynn McGuire

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal