Liste des Groupes | Revenir à cl c |
On Fri, 21 Mar 2025 20:50:51 -0700
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>bart <bc@freeuk.com> writes:>
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)?
>
That's the easiest question. And the right answer is "No, it does not."
In theory, printf extension that is a little less nice than Bart's, but
close, can be developed in C23 with no additional core language
features.
>
printf("%v\n", _TYIX(t));
>
Where _TYIX defined as
#define _TYIX(x) typeof_unqual((x)), (x)
>
In practice, it seems that C23 Standard does not say enough about
return value of typeof_unqual to make it feasible. Or, may be, my
source of information (en.cppreference.com/w/c/language/typeof)
is not up to date.
Les messages affichés proviennent d'usenet.