Path: csiph.com!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail From: nobody@example.org (Scott) Newsgroups: comp.lang.c Subject: Re: is there a way to ask a variable what it is? Date: Thu, 30 Jan 2020 15:59:55 GMT Organization: XMission http://xmission.com/ Message-ID: <5e32fa92.4262077640@core> References: <87lfpqrkit.fsf@bsb.me.uk> <87blqmqdek.fsf@bsb.me.uk> Injection-Info: news.xmission.com; posting-host="shell.xmission.com:2607:fa18:0:beef::4"; logging-data="17389"; mail-complaints-to="abuse@xmission.com" X-Newsreader: Forte Free Agent 1.21/32.243 Xref: csiph.com comp.lang.c:149532 On Wed, 29 Jan 2020 20:58:47 +0000, Bart wrote: >On 29/01/2020 20:49, Stefan Ram wrote: >> Ben Bacarisse writes: >>> Let me illustrate. If knowing the type is the top-level goal, the >>> answer is simple: you can't. >> >> Knowing the type of a variable? >> >> It can be read from the declaration. >> >> For example, >> >> double c; >> >> The type of »c« is double. > > >That's a simple example. Try: > > clock_t c; > >What's is the actual type of c? Or a little more challenging: I have one (silly) answer. $cat tmp.c #include int main(void) { clock_t x; printf("%c\n", x); } $gcc -Wformat tmp.c tmp.c: In function 'main': tmp.c:4:18: warning: format '%c' expects argument of type 'int', but argument 2 has type 'clock_t {aka long unsigned int}' [-Wformat=] printf("%c\n", x); ~^ %ld There, clock_t is long unsigned. I don't have any idea how to do this at runtime, or with any other compiler.