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 : 23. Mar 2025, 22:13:46
Autres entêtes
Organisation : None to speak of
Message-ID : <878qov8n79.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)
Michael S <already5chosen@yahoo.com> writes:
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."

I was asking about bart's language extension.  Do you have inside
information about that?

[...]

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.

I don't see how that would work.  typeof_unqual doesn't have a return
value; it yields a type, and can be used as a type name in a
declaration.  Unless I've missed something big, C23 doesn't let you pass
a type name as a function argument.

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

Date Sujet#  Auteur
24 Mar 26 o 

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal