0

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 ?

FI-Info
  • 635
  • 7
  • 16
  • 1
    Possible duplicate of [Is there a way to print struct members in a loop without naming each member in C?](https://stackoverflow.com/questions/27496245/is-there-a-way-to-print-struct-members-in-a-loop-without-naming-each-member-in-c) – ShadowRanger Sep 12 '19 at 02:28
  • use an IDE and just "go to definition" – phuclv Sep 23 '19 at 04:41

1 Answers1

0

You can read the man page, or you can read the header; there are no built-in introspection facilities in the C language that will inspect structs for their attributes in any convenient way.

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
  • 143,180
  • 12
  • 188
  • 271