How to get the struct info of a struct

by FI-Info   Last Updated September 12, 2019 02:26 AM

Is it possible to get the struct info (that is, the keys) of any struct? Or is required that you go to the manual page to read up what the actual structure is for that object. Take the following example:

struct stat stats;
stat(filepath, &stats);
printf("Size: %lld\n", stats.st_size);

Is it possible to do something like stats.keys(), or whatever a potentially equivalent operation would be to see the inner structure of a struct ?

Tags : c struct


Answers 1


You can read the man page, or you can read the header; there is no built-in introspection facilities in the C language.

In theory, if you compile the executable with debugging symbols a debugger might be able to tell you some of this (after loading and parsing the executable and its symbols), but that's generally going to be less convenient than just reading the docs.

ShadowRanger
ShadowRanger
September 12, 2019 02:25 AM

Related Questions


How to do unpack Tuple-Struct as with classic Tuple?

Updated August 10, 2017 23:26 PM

C int not being stored

Updated April 05, 2015 17:11 PM


Avoiding structure padding in c using attribute

Updated August 14, 2015 18:11 PM

How to send a struct over a pipe C++

Updated March 10, 2017 23:26 PM