Thread: Question on structure

  1. #1
    ignorance is blessing
    Join Date
    Sep 2006
    Posts
    13

    Question on structure

    Pardon me for my lack of knowledge in C programming but I am puzzle at one of the example in the book:
    Code:
    :
    struct employee2 {
        char firstName[20];
        char lastName[20];
        int age;
        char gender;
        double hourlySalary;
        struct employee2 person;   /*error*/
        struct employee2 *ePtr;   /*pointer*/
    };
    The book explains that a variable of type struct employee cannot be declared in the definition for struct employee. A pointer to struct employee, however. amybe included.
    Can anyone help explain why it is this case. Thanks a lot.

  2. #2
    Registered User
    Join Date
    Oct 2004
    Posts
    151
    Because that would create an infinitely recursive definition: a struct employee contains a struct employee, which contains a struct employee, which itself contains a struct employee...
    System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.

    Useful resources:
    comp.lang.c FAQ | C++ FQA Lite

  3. #3
    ignorance is blessing
    Join Date
    Sep 2006
    Posts
    13
    thanks for the reply zx-1

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 12-14-2007, 03:34 PM
  2. Simple C# structure question
    By sketch in forum C# Programming
    Replies: 4
    Last Post: 09-14-2007, 04:29 PM
  3. data structure question
    By miami_victor in forum C++ Programming
    Replies: 13
    Last Post: 12-31-2004, 12:56 AM
  4. Array and Structure Question
    By loopshot in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2004, 05:10 PM
  5. structure question
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 12-03-2001, 09:04 PM