Double ** pointer parameter?

Started by
35 comments, last by Zahlman 15 years, 3 months ago
Quote:Original post by danong
but my goal is trying to make this thing all happened within the call without out-of-scope manipulation of the size and declaration, question is, possible?


What, exactly, is "this thing" you are trying to make happen?
Advertisement
Your recursive function "works", as long as by "works" you mean "doesn't crash". Each time through the function creates two arrays and destroys one, and the value of ppNum (from main()) never changes. How could it? You pass it into a function and otherwise do not change it. Function arguments in C/C++ are passed by value, not by reference... even if they happen to be pointers. Or even pointers to pointers.
Quote:Original post by danong
but how'm i going to make the inner array exists after quitting the calls?
i'm guessing the inner one is declared as temporary and that's the reason why it ended up corrupting.
Sorry, I honestly have no clue what you're saying here.

Quote:Original post by danong
but my goal is trying to make this thing all happened within the call without out-of-scope manipulation of the size and declaration, question is, possible?
Or here.

Quote:Original post by danong
i'm doing this for some purpose,
don't ask about why and don't concern about the magic number,
Is this homework? I'm sorry, but I'm not willing to help someone who won't let me help them. And I won't do someone's homework. I've got my own to do.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Quote:Original post by danong
this is just a simplified testing demo i'd made for debugging use
So your actual code is more complicated and less debuggable than all that? I think, if you're willing to tell us the objective here, that we can demonstrate a safe way to do the same thing.
Quote:Original post by Sneftel
Your recursive function "works", as long as by "works" you mean "doesn't crash".


Am I missing something, or won't the first copy loop crash (probably, although technically the behavior would be undefined) when it derefences ppT?

Quote:
for(int i = 0; i != *pS; i++)
ppR = ppT; //<---ppT == NULL
Quote:Original post by MikeTacular
Quote:Original post by kittycat768
You made ppR point to ppT. Naturally ppT is an array of empty pointers. You then DESTROY the data that ppT points to. ppR turns into an array of invalid references. You then reallocate ppT to point to ppR which doesn't point to anything anymore. In the end neither point to anything.

Edited for clarity.
No he doesn't. He copies ppT into ppR, so when he destroys ppT, ppR is still valid.

I'd say the problem is because you are double dereferencing ppNum in main(). You never allocate memory for the 1-D array (the int* inner array), but you try to dereference it. If you could edit your post and put your code in [source][/source] tags, it would help a lot.

[edit]

ninja'd++;


Thanks mike,
i'd fixed the problem,
just as what you'd said.
you're helpful ;)

Thanks everyone,
God bless,

Regards,
Daniel.

Technical ..? then Master Non-Technical first ...
Quote:Original post by Driv3MeFar
Quote:Original post by Sneftel
Your recursive function "works", as long as by "works" you mean "doesn't crash".


Am I missing something, or won't the first copy loop crash (probably, although technically the behavior would be undefined) when it derefences ppT?

Quote:
for(int i = 0; i != *pS; i++)
ppR = ppT; //<---ppT == NULL

Ah, and how many times does the body of that for-loop execute?
Quote:Original post by danong
Thanks mike,
i'd fixed the problem,
just as what you'd said.
you're helpful ;)

Thanks everyone,
God bless,

Regards,
Daniel.
You're welcome, but please take into consideration everyone else's posts too. They pointed out some crucial bugs that I missed. Especially when you leak ppR's memory (as pointed out by Driv3MeFar).
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Some one please explain to me how ppR (an array of POINTERS) doesn't become an array of dangling references once he calls "delete[] ppT."
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------I once read that World of Warcraft is poor fishing simulator. I don't know about you but I catch a lot more fish in World of Warcraft than I do in real life.
Quote:Original post by Sneftel
Ah, and how many times does the body of that for-loop execute?


Durr, should've caught that... [embarrass]

This topic is closed to new replies.

Advertisement