print struct structure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bradawk
    New Member
    • Nov 2008
    • 1

    #1

    print struct structure

    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:

    Code:
    #include <stdio.h>
    # include <utmp.h>
    int main(int argc, char *argv[]) {
    struct utmp ut;
    int size;
    size = sizeof(ut);
    printf ("Size = %d\n", size);
    }
    This gives me the size of the structure, but I'd like to find each element. Is this possible?

    Thanks!

    Brad
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by bradawk
    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

    Comment

    • newb16
      Contributor
      • Jul 2008
      • 687

      #3
      There is no reflection in c(++). You need to read this header file with your own eyes.

      Comment

      Working...