Click here to Skip to main content
15,887,485 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to resolve Run time Error ? Pin
zhang80060520-Oct-06 0:12
zhang80060520-Oct-06 0:12 
AnswerRe: How to resolve Run time Error ? Pin
prasad_som20-Oct-06 0:23
prasad_som20-Oct-06 0:23 
QuestionLive Redirection Pin
rupert_durans19-Oct-06 23:49
rupert_durans19-Oct-06 23:49 
QuestionHow to change Project settings by using MSDEV Automation. Pin
Jijo.Raj19-Oct-06 23:31
Jijo.Raj19-Oct-06 23:31 
QuestionWhen to declare variables in C/C++ ? Pin
Mr.Brainley19-Oct-06 23:26
Mr.Brainley19-Oct-06 23:26 
AnswerRe: When to declare variables in C/C++ ? Pin
Cedric Moonen19-Oct-06 23:31
Cedric Moonen19-Oct-06 23:31 
AnswerRe: When to declare variables in C/C++ ? Pin
prasad_som19-Oct-06 23:40
prasad_som19-Oct-06 23:40 
AnswerRe: When to declare variables in C/C++ ? Pin
Jonathan [Darka]19-Oct-06 23:43
professionalJonathan [Darka]19-Oct-06 23:43 
If you create them at the top of a method and then at some point during the method you return without using the variable, then you have created it for no reason. This could be expensive if the creation takes a long time, or uses a lot of memory, or if the object has several base classes for example.

Typically you should only create a variable at the point you are going to use it, this an help the compiler perform its optimisations too.

It also makes the code easier to use and less prone to bugs as you cannot accidentally change the variable before first use if you create it only where you need it.

You can also control the scope of the variable so it only exists for as long as it needs to.

regards,



Darka [Xanya]

"I am not a slave to a god that doesn't exist."

AnswerRe: When to declare variables in C/C++ ? Pin
Christian Graus20-Oct-06 0:59
protectorChristian Graus20-Oct-06 0:59 
GeneralRe: When to declare variables in C/C++ ? Pin
benjymous20-Oct-06 1:23
benjymous20-Oct-06 1:23 
AnswerRe: When to declare variables in C/C++ ? Pin
David Crow20-Oct-06 3:18
David Crow20-Oct-06 3:18 
QuestionProblem with IHTMLInputElement Pin
georgekjolly19-Oct-06 23:05
georgekjolly19-Oct-06 23:05 
AnswerRe: Problem with IHTMLInputElement Pin
prasad_som19-Oct-06 23:18
prasad_som19-Oct-06 23:18 
AnswerRe: Problem with IHTMLInputElement Pin
Hamid_RT20-Oct-06 0:06
Hamid_RT20-Oct-06 0:06 
QuestionOLEDATA.MSO Format Pin
Reuven Nisser19-Oct-06 22:56
Reuven Nisser19-Oct-06 22:56 
QuestionPush-like checkboxes in WinXP Pin
Kiomuto19-Oct-06 22:47
Kiomuto19-Oct-06 22:47 
AnswerRe: Push-like checkboxes in WinXP Pin
Hamid_RT20-Oct-06 7:12
Hamid_RT20-Oct-06 7:12 
GeneralRe: Push-like checkboxes in WinXP Pin
Kiomuto21-Oct-06 5:51
Kiomuto21-Oct-06 5:51 
Questionreturning const member data Pin
minkowski19-Oct-06 22:41
minkowski19-Oct-06 22:41 
AnswerRe: returning const member data Pin
Cedric Moonen19-Oct-06 23:00
Cedric Moonen19-Oct-06 23:00 
GeneralRe: returning const member data Pin
minkowski19-Oct-06 23:01
minkowski19-Oct-06 23:01 
GeneralRe: returning const member data Pin
Cedric Moonen19-Oct-06 23:12
Cedric Moonen19-Oct-06 23:12 
AnswerRe: returning const member data Pin
prasad_som19-Oct-06 23:06
prasad_som19-Oct-06 23:06 
GeneralRe: returning const member data Pin
minkowski19-Oct-06 23:16
minkowski19-Oct-06 23:16 
QuestionBitmap Printing Pin
kk.tvm19-Oct-06 22:37
kk.tvm19-Oct-06 22:37 

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.