Thread: Structure Pointer to Structure

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    8

    Structure Pointer to Structure

    Hi C Coders,
    I have two query.
    Q1)

    I have two structures.
    Code:
    typedef struct _Object {
     char objName[132];
     int bit;
    }Object;
    
    typedef struct _Table {
      char tableName[132];
      char bit;
      Object *ob;
    } Table;
    
    Table *tbl;
    Table structure can contain array of structures of type Object.
    I do not know the number of Table and Object structures earlier
    How can I dynamically allocate the memory for these two structures, if necessary I can change the structure declaration also?

    Q2) I have two structures initialized as:
    Code:
    Object EOBJ_ObjTable1[] = {
    {"Obj1", 1111},
    {"Obj2",1212},
    };
    Object EOBJ_ObjTable2[] = {
    {"Obj1", 1213},
    };
    
    Table ETBL_Tab1 {
    "Tab1", 0000, &EOBJ_ObjTable1 
    };
    Table ETBL_Tab2 {
    "Tab2", 1111, &EOBJ_ObjTable2
    };
    If I declare the corresponding structures as Q1), then I am getting the warning as
    "Initialization makes integer from pointer without a cast"

    To remove the warnings, what should be changed in the structures.

    Thanks for your help in advance.

    Regards,
    Mayukh

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    I do not see = before initialization list of your tables
    also &EOBJ_ObjTable1 is pointer to array of objects not pointer to object

    EOBJ_ObjTable1 - is pointer to object (array name is coverted to the pointer to its first element as needed)
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. method returning a pointer to a structure
    By nacho4d in forum C++ Programming
    Replies: 3
    Last Post: 05-25-2009, 10:01 PM
  2. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  3. how to cast a char *mystring to a structure pointer ??
    By hanhao in forum C++ Programming
    Replies: 1
    Last Post: 03-29-2004, 08:59 AM
  4. Pointer to a structure
    By frenchfry164 in forum C Programming
    Replies: 5
    Last Post: 03-16-2002, 06:35 PM
  5. Pointer to next Structure
    By Garfield in forum C Programming
    Replies: 6
    Last Post: 09-16-2001, 03:18 PM