how to pass in a pointer to a pointer

This is a discussion on how to pass in a pointer to a pointer within the C Programming forums, part of the General Programming Boards category; Code: // sock_create signature ... int sock_create(int family, int type, int protocol, struct socket **res); struct bam { union am ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    14

    how to pass in a pointer to a pointer

    Code:
    // sock_create signature ... 
    int sock_create(int family, int type, int protocol, struct socket **res);
    
    struct bam {
        union am *lay;
    };
    
    struct cam {
        struct socket *skt; 
    };
    How do I pass in the skt member of 'struct cam' to function sock_create() which has arg that requires a pointer to a pointer?

    Code:
    	struct bam *bm;
    	struct cam *cm;
    
    	// ...
    
            cm = (struct cam *)bm->lay;
            
    	// cm->skt wrong here, but not sure how to pass in.
            ret = sock_create(AF_INET, SOCK_STREAM, IPPROTO_TCP, cm->skt);

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,639
    Take the address of the pointer
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    14
    Quote Originally Posted by laserlight View Post
    Take the address of the pointer
    I understand that's what I need to do, but confused on the syntax ... &(cm->skt)

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    2,054
    Yep, though you don't need the parentheses.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to pass function pointer as arg in c++
    By umen242 in forum C++ Programming
    Replies: 13
    Last Post: 10-21-2008, 02:09 AM
  2. Pass by reference vs pass by pointer
    By Non@pp in forum C++ Programming
    Replies: 10
    Last Post: 02-21-2006, 12:06 PM
  3. Should i pass address of pointer or just pointer???
    By howhy in forum C++ Programming
    Replies: 11
    Last Post: 09-02-2005, 04:05 AM
  4. Replies: 6
    Last Post: 11-29-2004, 07:50 AM
  5. A pointer to a character pointer array... can't pass
    By Lynux-Penguin in forum C Programming
    Replies: 9
    Last Post: 10-12-2003, 10:53 PM

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