Click here to Skip to main content
15,893,588 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Dump analysis Pin
HungryCPPDev11-Jun-12 20:23
HungryCPPDev11-Jun-12 20:23 
AnswerRe: Dump analysis Pin
Erudite_Eric6-Jun-12 22:32
Erudite_Eric6-Jun-12 22:32 
QuestionWhat's problem of my code?( create a random maze) Pin
jiuyejii6-Jun-12 0:45
jiuyejii6-Jun-12 0:45 
AnswerRe: What's problem of my code?( create a random maze) Pin
Chris Losinger6-Jun-12 1:14
professionalChris Losinger6-Jun-12 1:14 
GeneralRe: What's problem of my code?( create a random maze) Pin
jiuyejii6-Jun-12 1:36
jiuyejii6-Jun-12 1:36 
SuggestionRe: What's problem of my code?( create a random maze) Pin
David Crow6-Jun-12 2:36
David Crow6-Jun-12 2:36 
AnswerRe: What's problem of my code?( create a random maze) Pin
Maximilien6-Jun-12 2:46
Maximilien6-Jun-12 2:46 
AnswerRe: What's problem of my code?( create a random maze) Pin
Aescleal6-Jun-12 6:47
Aescleal6-Jun-12 6:47 
No idea what's causing your stack overflow, but as one of the previous posters mentioned (think it was David, sorry if I've got that wrong) it's probably related to recursion.

As to what the problem is with your code I can sum that up in one word. Abstraction. There's not a lot is there? When you write huge lumps of code how are other people meant to follow what you mean? Come to think of it how are you supposed to be able to follow it next week? And if you and other people are having problems think of the poor, literal minded compiler, he's having a nightmare [1].

So even if you don't want to do the whole OO thing, think about splitting your code up into nice little packets you and the rest of the world can understand. Here are some guidelines which have served me well:

- make each function only do one thing but make it do it well
- split loops and complex conditionals out into their own functions
- if a variable name is only a couple of characters long it's almost always too short
- if you've got more than 2 levels of indirection in an expression then that's too much. If you've got 2 it's probably still too much. Things like char **& are right out
- even if you're programming in "C like" C++ don't play about with memory directly. Let someone else do the heavy lifting. std::vector, std::unique_ptr and std::shared_ptr can cover about 99% of your dynamic memory requirements.

Interestingly you've got one complex conditional in it's own function. Cool! Keep that up and look for other places you can do the same sort of thing. FREX you've got the following segment of code:
C++
c--;
i=cti[c];
j=ctj[c];
cti[c+1]=0;

ctj[c+1]=0;
in four places. Think of a name to describe what this lot is up to and pack it away in a function. Do that a few more times and you might be starting to see where your code is going wrong.


[1] I've committed a cardinal sin here, I've anthropomorphised a computer. They don't like it when you do that.
GeneralRe: What's problem of my code?( create a random maze) Pin
Peter_in_27806-Jun-12 17:37
professionalPeter_in_27806-Jun-12 17:37 
GeneralRe: What's problem of my code?( create a random maze) Pin
jiuyejii6-Jun-12 18:49
jiuyejii6-Jun-12 18:49 
GeneralRe: What's problem of my code?( create a random maze) Pin
Aescleal6-Jun-12 23:52
Aescleal6-Jun-12 23:52 
AnswerRe: What's problem of my code?( create a random maze) Pin
Stefan_Lang8-Jun-12 4:19
Stefan_Lang8-Jun-12 4:19 
GeneralRe: What's problem of my code?( create a random maze) Pin
jiuyejii8-Jun-12 17:57
jiuyejii8-Jun-12 17:57 
QuestionMFC application being compiled on VS2012 Pin
YaronNir5-Jun-12 23:03
YaronNir5-Jun-12 23:03 
QuestionRe: MFC application being compiled on VS2012 Pin
David Crow6-Jun-12 2:37
David Crow6-Jun-12 2:37 
AnswerRe: MFC application being compiled on VS2012 Pin
YaronNir6-Jun-12 2:40
YaronNir6-Jun-12 2:40 
GeneralRe: MFC application being compiled on VS2012 Pin
tldcolli4-Aug-12 3:31
tldcolli4-Aug-12 3:31 
AnswerRe: MFC application being compiled on VS2012 Pin
tldcolli4-Aug-12 3:28
tldcolli4-Aug-12 3:28 
QuestionCode Executed Twice - OnHScroll() Pin
AmbiguousName5-Jun-12 21:42
AmbiguousName5-Jun-12 21:42 
AnswerRe: Code Executed Twice - OnHScroll() Pin
Chris Losinger6-Jun-12 1:17
professionalChris Losinger6-Jun-12 1:17 
AnswerRe: Code Executed Twice - OnHScroll() Pin
AmbiguousName6-Jun-12 1:35
AmbiguousName6-Jun-12 1:35 
GeneralRe: Code Executed Twice - OnHScroll() Pin
Chris Losinger6-Jun-12 1:38
professionalChris Losinger6-Jun-12 1:38 
GeneralRe: Code Executed Twice - OnHScroll() Pin
AmbiguousName6-Jun-12 1:40
AmbiguousName6-Jun-12 1:40 
GeneralRe: Code Executed Twice - OnHScroll() Pin
Chris Losinger6-Jun-12 2:08
professionalChris Losinger6-Jun-12 2:08 
AnswerRe: Code Executed Twice - OnHScroll() Pin
Malli_S6-Jun-12 21:43
Malli_S6-Jun-12 21:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.