0

I have a function using a pointer to a pointer to a structure:

int function(struct_A ** mystructA);

It worked when i used it with my declared struct:

struct_A *mystructA;
function(&mystructA);

however, impossible to use my structure throught another structure:

struct struct_B{
    struct_A *mystructA;
}

struct_B mystructB;
function( (&mystructB)->mystructA );    //this line cause me a segfault

I am struggling here, any idea where it could come from?

3
  • &(mystructB->mystructA) Commented Oct 14, 2020 at 17:11
  • if you want to use it this strange way function( &(&mystructB)->mystructA ); Commented Oct 14, 2020 at 17:36
  • Thanks it did the trick! Commented Oct 15, 2020 at 12:54

2 Answers 2

1
struct struct_B{
    struct_A *mystructA;
}

struct struct_B mystructB;
struct struct_B *mystructBptr;

/* .... */

function( &mystructB.mystructA );
function( &(&mystructB) -> mystructA );
function( &mystructBptr -> mystructA );
Sign up to request clarification or add additional context in comments.

Comments

1

It seems you mean the following

struct struct_B{
    struct_A *mystructA;
}

struct struct_B mystructB;
function( &mystructB.mystructA );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.