Like Tree1Likes
  • 1 Post By msh

Pointer to a pointer struct

This is a discussion on Pointer to a pointer struct within the C Programming forums, part of the General Programming Boards category; I'm working on a project that involves double pointers INSIDE a struct, and I'm kinda confused. Code: typedef struct block ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    21

    Pointer to a pointer struct

    I'm working on a project that involves double pointers INSIDE a struct, and I'm kinda confused.

    Code:
    typedef struct block {  
                              
      unsigned int start_address;
     unsigned int end_address;  
     ....  
    struct block **successors;  //array of successor block
    
     } BLOCK;


    edit: First off, how do you link such structures together??
    Last edited by acpower; 05-07-2012 at 08:46 AM.

  2. #2
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Do everyone a favor and lose the typedef.

    Generally, variables of type pointer-to-pointer are asking you to assign an address of a pointer to them.
    Code:
    struct block b;
    struct block *succ = malloc(sizeof(*succ));
    
    b.successor = ≻
    acpower likes this.
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    21
    That's how the code was given to us. But anyway I think I got it, I'll see how it goes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 05-12-2011, 02:02 AM
  2. Replies: 3
    Last Post: 10-30-2009, 05:41 PM
  3. Replies: 6
    Last Post: 05-15-2009, 09:38 AM
  4. Replies: 4
    Last Post: 08-28-2007, 12:51 AM
  5. Pointer points to struct pointer
    By gogo in forum C Programming
    Replies: 4
    Last Post: 11-27-2001, 12:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21