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?
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?
Quote:Original post by danongSorry, I honestly have no clue what you're saying here.
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.
Quote:Original post by danongOr here.
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?
Quote:Original post by danongIs 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.
i'm doing this for some purpose,
don't ask about why and don't concern about the magic number,
Quote:Original post by danongSo 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.
this is just a simplified testing demo i'd made for debugging use
Quote:Original post by Sneftel
Your recursive function "works", as long as by "works" you mean "doesn't crash".
Quote:
for(int i = 0; i != *pS; i++)
ppR = ppT; //<---ppT == NULL
Quote:Original post by MikeTacularQuote:Original post by kittycat768No he doesn't. He copies ppT into ppR, so when he destroys ppT, ppR is still valid.
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.
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++;
Quote:Original post by Driv3MeFarQuote: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 danongYou'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).
Thanks mike,
i'd fixed the problem,
just as what you'd said.
you're helpful ;)
Thanks everyone,
God bless,
Regards,
Daniel.
Quote:Original post by Sneftel
Ah, and how many times does the body of that for-loop execute?