By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,434 Members | 1,878 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,434 IT Pros & Developers. It's quick & easy.

print struct structure

P: 1
It has been a long while since I did any C programming. I am trying to read the utmp.h header on RHEL vs 5 but I am getting a little lost with the branching. I wanted to write a simple program that would create a struct of type utmp and then would print out each element name and type. Such as, "the first element is called ut_type and is an integer." I have:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. # include <utmp.h>
  3. int main(int argc, char *argv[]) {
  4. struct utmp ut;
  5. int size;
  6. size = sizeof(ut);
  7. printf ("Size = %d\n", size);
  8. }
This gives me the size of the structure, but I'd like to find each element. Is this possible?

Thanks!

Brad
Nov 18 '08 #1
Share this Question
Share on Google+
2 Replies


Expert 10K+
P: 11,448
This gives me the size of the structure, but I'd like to find each element. Is this possible?
Nope, not in C; it's a pure compiled language and names only have a meaning
during compile time. During runtime an actual struct is just a sequence of bytes
(chars) that you treat as a struct, i.e. the bare metal doesn't care less.

kind regards,

Jos
Nov 18 '08 #2

100+
P: 687
There is no reflection in c(++). You need to read this header file with your own eyes.
Nov 18 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.