Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #144098
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Print the values of the members of a structure |
| Date | 2019-05-29 12:16 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87a7f5jytk.fsf@bsb.me.uk> (permalink) |
| References | <46591b57-d339-492b-bd14-28d5cf0a6448@googlegroups.com> <structs-20190529111955@ram.dialup.fu-berlin.de> <6rtHE.562383$QT2.130500@fx16.am4> |
Bart <bc@freeuk.com> writes:
> On 29/05/2019 11:21, Stefan Ram wrote:
>> A Google poster writes:
>>> Subject: Print the values of the members of a structure
>>
>> One cannot directly print structure members automatically in
>> standard C. Some debuggers or implementations might provide
>> such a feature as an extension.
>>
>> One can implement such a feature in C by adding run-time
>> information about the structs or implementing custom records.
>> For example, when one uses the Python run-time, one then can
>> automatically print Python records (objects) using C code.
>
>
> You don't need runtime info, not when the format string is constant
> and known to the compiler.
>
> For example:
>
> printf("%S", a);
>
> could be compiled as though the user had written:
>
> printf("%d %s", a.age, a,name);
>
> There will still be plenty of problems: no control over formats; what
> to do with unions; how to deal with arrays. But for simple cases like
> this, it can handy.
The OP is happy to provide the format, just not the member names. It's
not a massive problem, but a simple solution would be to provide
something like a syntax "macro": __MEMBERS__(a) which expands to the
list of names. Of course it can't be a macro in the usual sense because
of how they are currently specified. Types don't exist when macros are
expanded, much less declarations that link names to types.
--
Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Print the values of the members of a structure ab.avramidis@cloudsolutions.co.uk - 2019-05-29 02:19 -0700
Re: Print the values of the members of a structure mark.bluemel@gmail.com - 2019-05-29 02:32 -0700
Re: Print the values of the members of a structure Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2019-05-29 08:28 -0600
Re: Print the values of the members of a structure ab.avramidis@cloudsolutions.co.uk - 2019-05-29 07:35 -0700
Re: Print the values of the members of a structure Bart <bc@freeuk.com> - 2019-05-29 11:47 +0100
Re: Print the values of the members of a structure Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-05-29 12:16 +0100
Re: Print the values of the members of a structure Bart <bc@freeuk.com> - 2019-05-29 15:45 +0100
Re: Print the values of the members of a structure Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2019-05-29 08:34 -0600
Re: Print the values of the members of a structure Clifford Heath <no.spam@please.net> - 2019-05-30 11:55 +1000
Re: Print the values of the members of a structure Clifford Heath <no.spam@please.net> - 2019-06-02 22:58 +1000
Re: Print the values of the members of a structure Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-06-02 17:09 +0100
Re: Print the values of the members of a structure Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-06-02 23:05 -0700
Re: Print the values of the members of a structure Clifford Heath <no.spam@please.net> - 2019-06-03 17:38 +1000
Re: Print the values of the members of a structure James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-05-29 07:57 -0400
csiph-web