0

So, I have one function like the following:

void myfunction1(int *number)
{
    ...
}

And I have:

void myfunction2(int *number)
{
    ...
    myfunction1(&number);
}

When I run the code I get the error:

warning: passing argument 1 of ‘myfunction1’ from incompatible pointer type

So I changed my second function to:

void myfunction2(int *number)
{
    ...
    myfunction1(&(*number));
}

And I got:

dev(887) malloc: *** error for object 0x7fd400403810: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

Any ideas?

1
  • 2
    just myfunction1(number); Commented Jul 28, 2013 at 20:49

3 Answers 3

2

number already has type int* so you can pass it directly to myfunction1 with myfunction1(number). The malloc error has nothing to do with any code that you have shown.

Sign up to request clarification or add additional context in comments.

Comments

2

Number is already a pointer to int. Therefore if you do &number where number is an int* you are passing a pointer to a pointer to int.

void myfunction2(int *number)
{
    myfunction1(number);
}

will do the trick

Comments

0

basically what the others are saying is this is what you should do:

void myfunction2(int *number)
{
    ...
    myfunction1(number);
}

inside myfunction2, number is already a pointer, so pass that as it is to myfunction1

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.