Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #149463 > unrolled thread
| Started by | T <T@invalid.invalid> |
|---|---|
| First post | 2020-01-28 19:19 -0800 |
| Last post | 2020-01-29 11:55 -0800 |
| Articles | 20 on this page of 44 — 16 participants |
Back to article view | Back to comp.lang.c
is there a way to ask a variable what it is? T <T@invalid.invalid> - 2020-01-28 19:19 -0800
Re: is there a way to ask a variable what it is? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-01-29 03:47 +0000
Re: is there a way to ask a variable what it is? T <T@invalid.invalid> - 2020-01-28 20:20 -0800
Re: is there a way to ask a variable what it is? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-01-29 19:18 +0000
Re: is there a way to ask a variable what it is? Bart <bc@freeuk.com> - 2020-01-29 20:58 +0000
Re: is there a way to ask a variable what it is? nobody@example.org (Scott) - 2020-01-30 15:59 +0000
Re: is there a way to ask a variable what it is? scott@slp53.sl.home (Scott Lurndal) - 2020-01-30 16:35 +0000
Re: is there a way to ask a variable what it is? Siri Cruise <chine.bleu@yahoo.com> - 2020-01-28 21:55 -0800
Re: is there a way to ask a variable what it is? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-01-30 00:24 +0000
solved: Re: is there a way to ask a variable what it is? T <T@invalid.invalid> - 2020-01-29 21:51 -0800
Re: solved: Re: is there a way to ask a variable what it is? fir <profesor.fir@gmail.com> - 2020-01-30 03:16 -0800
Re: is there a way to ask a variable what it is? Ian Collins <ian-news@hotmail.com> - 2020-01-29 17:28 +1300
Re: is there a way to ask a variable what it is? T <T@invalid.invalid> - 2020-01-28 20:55 -0800
Re: is there a way to ask a variable what it is? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-01-29 06:49 +0000
Re: is there a way to ask a variable what it is? Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-29 08:08 +0100
Re: is there a way to ask a variable what it is? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-01-30 00:14 +0000
solved: Re: is there a way to ask a variable what it is? T <T@invalid.invalid> - 2020-01-29 21:51 -0800
Re: is there a way to ask a variable what it is? Robert Wessel <robertwessel2@yahoo.com> - 2020-01-28 22:36 -0600
Re: is there a way to ask a variable what it is? T <T@invalid.invalid> - 2020-01-28 20:55 -0800
Re: is there a way to ask a variable what it is? Manfred <noname@add.invalid> - 2020-01-29 13:22 +0100
Re: is there a way to ask a variable what it is? David Brown <david.brown@hesbynett.no> - 2020-01-29 13:57 +0100
Re: is there a way to ask a variable what it is? Manfred <noname@add.invalid> - 2020-01-29 17:47 +0100
Re: is there a way to ask a variable what it is? David Brown <david.brown@hesbynett.no> - 2020-01-30 12:06 +0100
Re: is there a way to ask a variable what it is? scott@slp53.sl.home (Scott Lurndal) - 2020-01-29 15:10 +0000
Re: is there a way to ask a variable what it is? Manfred <noname@add.invalid> - 2020-01-29 17:07 +0100
Re: is there a way to ask a variable what it is? Siri Cruise <chine.bleu@yahoo.com> - 2020-01-28 21:52 -0800
Re: is there a way to ask a variable what it is? Bart <bc@freeuk.com> - 2020-01-29 11:11 +0000
Re: is there a way to ask a variable what it is? Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-29 13:30 +0100
Re: is there a way to ask a variable what it is? Bart <bc@freeuk.com> - 2020-01-29 12:44 +0000
Re: is there a way to ask a variable what it is? Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-29 14:03 +0100
Re: is there a way to ask a variable what it is? gazelle@shell.xmission.com (Kenny McCormack) - 2020-01-29 14:03 +0000
Re: is there a way to ask a variable what it is? Bart <bc@freeuk.com> - 2020-01-29 14:30 +0000
Re: is there a way to ask a variable what it is? Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-29 15:45 +0100
Re: is there a way to ask a variable what it is? Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-29 16:28 +0100
Re: is there a way to ask a variable what it is? T <T@invalid.invalid> - 2020-01-29 08:35 -0800
Re: is there a way to ask a variable what it is? Bart <bc@freeuk.com> - 2020-01-29 17:34 +0000
Re: is there a way to ask a variable what it is? Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-29 18:48 +0100
Re: is there a way to ask a variable what it is? Thiago Adams <thiago.adams@gmail.com> - 2020-01-29 04:43 -0800
Re: is there a way to ask a variable what it is? David Brown <david.brown@hesbynett.no> - 2020-01-29 14:46 +0100
Re: is there a way to ask a variable what it is? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-01-29 15:15 +0000
Re: is there a way to ask a variable what it is? fir <profesor.fir@gmail.com> - 2020-01-29 08:11 -0800
Re: is there a way to ask a variable what it is? T <T@invalid.invalid> - 2020-01-29 08:38 -0800
Re: is there a way to ask a variable what it is? Bart <bc@freeuk.com> - 2020-01-29 11:23 +0000
Re: is there a way to ask a variable what it is? John Bode <jfbode1029@gmail.com> - 2020-01-29 11:55 -0800
Page 1 of 3 [1] 2 3 Next page →
| From | T <T@invalid.invalid> |
|---|---|
| Date | 2020-01-28 19:19 -0800 |
| Subject | is there a way to ask a variable what it is? |
| Message-ID | <r0qtkb$3qj$1@dont-email.me> |
Hi All,
Trivia question:
In C, after you declare a variable, is there a way
to turn around and ask it what that variable is?
Some thing like Raku's
> my uint $u; say $u.^name
Int
only correct?
Many thanks,
-T
[toc] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2020-01-29 03:47 +0000 |
| Message-ID | <87lfpqrkit.fsf@bsb.me.uk> |
| In reply to | #149463 |
T <T@invalid.invalid> writes: > Trivia question: > > In C, after you declare a variable, is there a way > to turn around and ask it what that variable is? You seem to mean what type it is. No. There is no way to find that out. This prompts a follow-up question. What would you want to do with it? It's possible that what you want to achieve could be done in some other way. > Some thing like Raku's > > > my uint $u; say $u.^name > Int > > only correct? I don't think that's wrong, but it's not topical here. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | T <T@invalid.invalid> |
|---|---|
| Date | 2020-01-28 20:20 -0800 |
| Message-ID | <r0r17d$jbq$1@dont-email.me> |
| In reply to | #149464 |
On 2020-01-28 19:47, Ben Bacarisse wrote: > T <T@invalid.invalid> writes: > >> Trivia question: >> >> In C, after you declare a variable, is there a way >> to turn around and ask it what that variable is? > > You seem to mean what type it is. No. There is no way to find that > out. > > This prompts a follow-up question. What would you want to do with it? > It's possible that what you want to achieve could be done in some other > way. In Raku, I can define a variable as a subset, such as a string and an integer. I ask the variable what it is to determine what details are inside it > >> Some thing like Raku's >> >> > my uint $u; say $u.^name >> Int >> >> only correct? > > I don't think that's wrong, but it's not topical here. Techincally, it is not wrong. This is like Quantum Observation where observing the thing changes it. ^name changes the variable from unit (unsigned integer) to UInt (magical unsigned integer that can have as many byte in it as your heart desires). Only You have no clue the variable got changed. But the result is always consistent. Get a load of this! > my UInt $x = 0xFFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF; 95780971304118053647396689196894323976171195136475135 The reason for the trivia question is that Raku is written in C and if you ask too technical a question, you get C quoted at you. -T
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2020-01-29 19:18 +0000 |
| Message-ID | <87blqmqdek.fsf@bsb.me.uk> |
| In reply to | #149465 |
T <T@invalid.invalid> writes: > On 2020-01-28 19:47, Ben Bacarisse wrote: >> T <T@invalid.invalid> writes: >> >>> Trivia question: >>> >>> In C, after you declare a variable, is there a way >>> to turn around and ask it what that variable is? >> >> You seem to mean what type it is. No. There is no way to find that >> out. >> >> This prompts a follow-up question. What would you want to do with it? >> It's possible that what you want to achieve could be done in some other >> way. > > In Raku, I can define a variable as a subset, such > as a string and an integer. I ask the variable what > it is to determine what details are inside it That was not really my point. If you have a C problem, this is the place to ask, but the question has to be about programming goals, not how to I, in C, all the things I do in Raku. Let me illustrate. If knowing the type is the top-level goal, the answer is simple: you can't. But if you want to kow the type in order to find out its range, you may be able to find suitable alternatives in C. <cut Raku stuff> -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Bart <bc@freeuk.com> |
|---|---|
| Date | 2020-01-29 20:58 +0000 |
| Message-ID | <emmYF.251862$_R5.228244@fx19.am4> |
| In reply to | #149506 |
On 29/01/2020 20:49, Stefan Ram wrote:
> Ben Bacarisse <ben.usenet@bsb.me.uk> 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:
#ifdef __GNUC__
clock_t c;
#elif MAC1 // set via -D compiler option
float c;
#elif __LINE__ == 17
char* c;
#else
long long int c;
#endif
Or you want to know whether pointers to A and B will be compatible:
int64_t A;
long long B;
[toc] | [prev] | [next] | [standalone]
| From | nobody@example.org (Scott) |
|---|---|
| Date | 2020-01-30 15:59 +0000 |
| Message-ID | <5e32fa92.4262077640@core> |
| In reply to | #149510 |
On Wed, 29 Jan 2020 20:58:47 +0000, Bart <bc@freeuk.com> wrote:
>On 29/01/2020 20:49, Stefan Ram wrote:
>> Ben Bacarisse <ben.usenet@bsb.me.uk> 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 <stdio.h>
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.
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2020-01-30 16:35 +0000 |
| Message-ID | <HBDYF.30903$Ys3.23851@fx21.iad> |
| In reply to | #149532 |
nobody@example.org (Scott) writes:
>On Wed, 29 Jan 2020 20:58:47 +0000, Bart <bc@freeuk.com> wrote:
>
>>On 29/01/2020 20:49, Stefan Ram wrote:
>>> Ben Bacarisse <ben.usenet@bsb.me.uk> 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 <stdio.h>
>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.
>
There's always the source:
The <sys/types.h> header shall define at least the following types:
blkcnt_t
Used for file block counts.
blksize_t
Used for block sizes.
clock_t
Used for system times in clock ticks or CLOCKS_PER_SEC; see <time.h>.
...
Additionally:
* clock_t shall be an integer or real-floating type.
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html
Albeit I've never seen it implemented as a real-floating type.
[toc] | [prev] | [next] | [standalone]
| From | Siri Cruise <chine.bleu@yahoo.com> |
|---|---|
| Date | 2020-01-28 21:55 -0800 |
| Message-ID | <chine.bleu-AE8637.21552528012020@reader.eternal-september.org> |
| In reply to | #149464 |
In article <87lfpqrkit.fsf@bsb.me.uk>, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote: > This prompts a follow-up question. What would you want to do with it? > It's possible that what you want to achieve could be done in some other > way. Implement a fprintf like macro in m4. Rather than hope you got the right basic type (int, double, etc) and the right length (long, long long, short), the macro can encode the parameters types into the code. The implementation will know exactly what's on the var-args. -- :-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted. @ 'I desire mercy, not sacrifice.' /|\ The first law of discordiamism: The more energy This post / \ to make order is nore energy made into entropy. insults Islam. Mohammed
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2020-01-30 00:24 +0000 |
| Message-ID | <87tv4dpz9q.fsf@bsb.me.uk> |
| In reply to | #149471 |
Siri Cruise <chine.bleu@yahoo.com> writes: > In article <87lfpqrkit.fsf@bsb.me.uk>, > Ben Bacarisse <ben.usenet@bsb.me.uk> wrote: > >> This prompts a follow-up question. What would you want to do with it? >> It's possible that what you want to achieve could be done in some other >> way. > > Implement a fprintf like macro in m4. Rather than hope you got > the right basic type (int, double, etc) and the right length > (long, long long, short), the macro can encode the parameters > types into the code. The implementation will know exactly what's > on the var-args. Yes. My "you" was literal and directed at the OP. I (and you and others) can come up with all sorts of examples where this information could be useful, but I wanted to move the OP onto something we might be able to help with by offering alternative techniques rather than simply saying "computer says no". (I say "yes" but I did not really understand your example. Just a type-checked version of printf would be a simple use for run-time type information.) -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | T <T@invalid.invalid> |
|---|---|
| Date | 2020-01-29 21:51 -0800 |
| Subject | solved: Re: is there a way to ask a variable what it is? |
| Message-ID | <r0tqs7$kuf$1@dont-email.me> |
| In reply to | #149515 |
On 2020-01-29 16:24, Ben Bacarisse wrote: > Siri Cruise <chine.bleu@yahoo.com> writes: > >> In article <87lfpqrkit.fsf@bsb.me.uk>, >> Ben Bacarisse <ben.usenet@bsb.me.uk> wrote: >> >>> This prompts a follow-up question. What would you want to do with it? >>> It's possible that what you want to achieve could be done in some other >>> way. >> >> Implement a fprintf like macro in m4. Rather than hope you got >> the right basic type (int, double, etc) and the right length >> (long, long long, short), the macro can encode the parameters >> types into the code. The implementation will know exactly what's >> on the var-args. > > Yes. My "you" was literal and directed at the OP. I (and you and > others) can come up with all sorts of examples where this information > could be useful, but I wanted to move the OP onto something we might be > able to help with by offering alternative techniques rather than simply > saying "computer says no". > > (I say "yes" but I did not really understand your example. Just a > type-checked version of printf would be a simple use for run-time type > information.) > Gee wiz, it was just a trivia question. The answer was"no". That was all I was interest in.
[toc] | [prev] | [next] | [standalone]
| From | fir <profesor.fir@gmail.com> |
|---|---|
| Date | 2020-01-30 03:16 -0800 |
| Subject | Re: solved: Re: is there a way to ask a variable what it is? |
| Message-ID | <1cea6c91-03b4-469a-a0ef-695629ddf043@googlegroups.com> |
| In reply to | #149516 |
W dniu czwartek, 30 stycznia 2020 06:51:12 UTC+1 użytkownik T napisał: > On 2020-01-29 16:24, Ben Bacarisse wrote: > > Siri Cruise <chine.bleu@yahoo.com> writes: > > > >> In article <87lfpqrkit.fsf@bsb.me.uk>, > >> Ben Bacarisse <ben.usenet@bsb.me.uk> wrote: > >> > >>> This prompts a follow-up question. What would you want to do with it? > >>> It's possible that what you want to achieve could be done in some other > >>> way. > >> > >> Implement a fprintf like macro in m4. Rather than hope you got > >> the right basic type (int, double, etc) and the right length > >> (long, long long, short), the macro can encode the parameters > >> types into the code. The implementation will know exactly what's > >> on the var-args. > > > > Yes. My "you" was literal and directed at the OP. I (and you and > > others) can come up with all sorts of examples where this information > > could be useful, but I wanted to move the OP onto something we might be > > able to help with by offering alternative techniques rather than simply > > saying "computer says no". > > > > (I say "yes" but I did not really understand your example. Just a > > type-checked version of printf would be a simple use for run-time type > > information.) > > > > Gee wiz, it was just a trivia question. The answer was"no". > That was all I was interest in. this is discusion goups meant to be be sometimes suitable for discussing more indepth problems if you want such trivial answers more suitable place is irc (here is some chanell for c on freenode?) you will get that answers in a pack in a seconds via irc
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2020-01-29 17:28 +1300 |
| Message-ID | <h9cfvbF25s3U14@mid.individual.net> |
| In reply to | #149463 |
On 29/01/2020 16:19, T wrote: > Hi All, > > Trivia question: > > In C, after you declare a variable, is there a way > to turn around and ask it what that variable is? You are looking for reflection, which C lacks. -- Ian.
[toc] | [prev] | [next] | [standalone]
| From | T <T@invalid.invalid> |
|---|---|
| Date | 2020-01-28 20:55 -0800 |
| Message-ID | <r0r37k$r04$1@dont-email.me> |
| In reply to | #149466 |
On 2020-01-28 20:28, Ian Collins wrote: > On 29/01/2020 16:19, T wrote: >> Hi All, >> >> Trivia question: >> >> In C, after you declare a variable, is there a way >> to turn around and ask it what that variable is? > > You are looking for reflection, which C lacks. > Not sure what a reflection. I really don't think C can do this without have a structure assigned to every variable.
[toc] | [prev] | [next] | [standalone]
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2020-01-29 06:49 +0000 |
| Message-ID | <slrnr32ao5.km3.grahn+nntp@frailea.sa.invalid> |
| In reply to | #149468 |
On Wed, 2020-01-29, T wrote: > On 2020-01-28 20:28, Ian Collins wrote: >> On 29/01/2020 16:19, T wrote: >>> Hi All, >>> >>> Trivia question: >>> >>> In C, after you declare a variable, is there a way >>> to turn around and ask it what that variable is? >> >> You are looking for reflection, which C lacks. > > Not sure what a reflection. He simply gave you the technical name for the feature you asked for. So you can e.g. read about it if you want to. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o .
[toc] | [prev] | [next] | [standalone]
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2020-01-29 08:08 +0100 |
| Message-ID | <r0rb11$qh6$1@news.albasani.net> |
| In reply to | #149468 |
>>> In C, after you declare a variable, is there a way >>> to turn around and ask it what that variable is? >> You are looking for reflection, which C lacks. > Not sure what a reflection. You're asking for a feature and don't know what it's good for.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2020-01-30 00:14 +0000 |
| Message-ID | <87zhe5pzqf.fsf@bsb.me.uk> |
| In reply to | #149468 |
T <T@invalid.invalid> writes: > On 2020-01-28 20:28, Ian Collins wrote: >> On 29/01/2020 16:19, T wrote: >>> Hi All, >>> >>> Trivia question: >>> >>> In C, after you declare a variable, is there a way >>> to turn around and ask it what that variable is? >> >> You are looking for reflection, which C lacks. > > Not sure what a reflection. Reflection in programming languages are those features that allow programs to talk about programs (or, more often, parts of programs). C has almost no features that fit that definition. > I really don't think C can do this without have a > structure assigned to every variable. Your "this" is vague, but C is a statically typed language so all type information, and everything easily derived from type information, is known at compile time. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | T <T@invalid.invalid> |
|---|---|
| Date | 2020-01-29 21:51 -0800 |
| Subject | solved: Re: is there a way to ask a variable what it is? |
| Message-ID | <r0tqt4$kuf$2@dont-email.me> |
| In reply to | #149514 |
On 2020-01-29 16:14, Ben Bacarisse wrote: > Your "this" is vague, but C is a statically typed language so all type > information, and everything easily derived from type information, is > known at compile time. Perfect.
[toc] | [prev] | [next] | [standalone]
| From | Robert Wessel <robertwessel2@yahoo.com> |
|---|---|
| Date | 2020-01-28 22:36 -0600 |
| Message-ID | <ar223fdb4s1n4tgks99ni798ftjuot4i12@4ax.com> |
| In reply to | #149463 |
On Tue, 28 Jan 2020 19:19:38 -0800, T <T@invalid.invalid> wrote: >Hi All, > >Trivia question: > >In C, after you declare a variable, is there a way >to turn around and ask it what that variable is? > >Some thing like Raku's > > > my uint $u; say $u.^name > Int > >only correct? As Ben mentioned, there's no such feature in C. Reflection was considered for C++20, but was deferred until the next major revision.
[toc] | [prev] | [next] | [standalone]
| From | T <T@invalid.invalid> |
|---|---|
| Date | 2020-01-28 20:55 -0800 |
| Message-ID | <r0r38m$r04$2@dont-email.me> |
| In reply to | #149467 |
On 2020-01-28 20:36, Robert Wessel wrote: > On Tue, 28 Jan 2020 19:19:38 -0800, T <T@invalid.invalid> wrote: > >> Hi All, >> >> Trivia question: >> >> In C, after you declare a variable, is there a way >> to turn around and ask it what that variable is? >> >> Some thing like Raku's >> >> > my uint $u; say $u.^name >> Int >> >> only correct? > > > As Ben mentioned, there's no such feature in C. Reflection was > considered for C++20, but was deferred until the next major revision. > Dang!
[toc] | [prev] | [next] | [standalone]
| From | Manfred <noname@add.invalid> |
|---|---|
| Date | 2020-01-29 13:22 +0100 |
| Message-ID | <r0rteo$1ep6$1@gioia.aioe.org> |
| In reply to | #149469 |
On 1/29/2020 5:55 AM, T wrote: > On 2020-01-28 20:36, Robert Wessel wrote: >> On Tue, 28 Jan 2020 19:19:38 -0800, T <T@invalid.invalid> wrote: >> >>> Hi All, >>> >>> Trivia question: >>> >>> In C, after you declare a variable, is there a way >>> to turn around and ask it what that variable is? >>> >>> Some thing like Raku's >>> >>> > my uint $u; say $u.^name >>> Int >>> >>> only correct? >> >> >> As Ben mentioned, there's no such feature in C. Reflection was >> considered for C++20, but was deferred until the next major revision. >> > > Dang! It may be worth noting (as Bart mentioned) that C has a static type system, so the type of each variable is always known. For this reason C does not need reflection. The type system of C++ is statically checked as well, however, being considerably richer than C, it features RTTI, and may have some use for reflection. No urge for it though, as it can be deduced from Robert's comment.
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.c
csiph-web