Liste des Groupes | Revenir à cl c |
bart <bc@freeuk.com> writes:You missed the "?".On 21/03/2025 19:04, Keith Thompson wrote:First you talked about compilers grinding to a halt, then you talkedbart <bc@freeuk.com> writes:>On 21/03/2025 01:47, Keith Thompson wrote:If you want <stdint.h> and <inttypes.h> headers that work correctlybart <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?
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.
>Complicated headers that work.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.
[...\
>I think your response clarifies matters. Nobody cares, even asIf compilers ground to a halt, I would certainly care. They don't.
compilers grind to a halt under all preprocessing.
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.
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 wouldLet me ask it again: so ploughing through a third of a million lines of code across hundreds of #includes, even at the faster throughput compared with compiling code, for a module of a few hundred lines, will have little impact?
not be impacted. Do not put words into my mouth again.
My feature was a proof of concept. The 60 lines of code used to test it worked specifically for 'printf', and didn't attempt to parse additional attributes like field widths (I wasn't implementing half of printf).printf("%v\n", t); # (used to be '?'; changed to 'v')That's nice. Seriously, it's nice. If it were added to a future
}
>
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'.
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.
an integer of arbitrary type in hexadecimal in a right-justifiedAs I said the test was 60 lines of ad hoc code. It's not going to be wildly complicated. As a language feature, somebody would need to write a specification.
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 otherThe problem with Print is that it is a language feature that can take a arbitrary number of arguments, all of different types. Some may need formatting info.
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.
Sorry, I was being sarcastic. There were languages in the 60s where you could just say 'print x' and it knew how to stringify x whatever its type was. My first language using an 8KB compiler had such a Print (though not many types).That's amazing.Not particularly.
C has programmer-defined operator (and function)You get an interesting set of error messages if you write >> instead of <<.
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.)
Les messages affichés proviennent d'usenet.