Click here to Skip to main content
15,895,142 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
JokeRe: simple Question Pin
toxcct5-Sep-05 1:07
toxcct5-Sep-05 1:07 
GeneralRe: simple Question Pin
kakan5-Sep-05 0:36
professionalkakan5-Sep-05 0:36 
AnswerRe: simple Question Pin
ThatsAlok5-Sep-05 1:12
ThatsAlok5-Sep-05 1:12 
GeneralRe: simple Question Pin
kakan5-Sep-05 1:35
professionalkakan5-Sep-05 1:35 
AnswerRe: simple Question Pin
ThatsAlok5-Sep-05 3:12
ThatsAlok5-Sep-05 3:12 
AnswerRe: simple Question Pin
Marc Soleda5-Sep-05 0:09
Marc Soleda5-Sep-05 0:09 
AnswerRe: simple Question Pin
Eytukan5-Sep-05 0:46
Eytukan5-Sep-05 0:46 
AnswerRe: simple Question Pin
Gary R. Wheeler5-Sep-05 5:47
Gary R. Wheeler5-Sep-05 5:47 
The behavior here is dependent upon the compiler implementation. When you define a variable, two things happen. One, memory is allocated to store the variable, and two, the variable's constructor is called to initialize it.

For atomic data types, the compiler may in effect perform a single static allocation, just prior to the top of the loop. This allocation occurs by virtue of assigning the variable 'x' a fixed offset from the stack pointer.

Regardless of how the memory is allocated, the compiler will call the constructor at the beginning of each iteration. Since 'x' is of type int, the constructor doesn't do anything.

How the compiler allocates memory in this case should be immaterial to you. When a variable is defined inside the loop, you should treat it as if it were newly constructed. For simple int values, this means the variable is uninitialized, and you can't rely on it containing the results from the previous iteration.


Software Zen: delete this;
QuestionHow to use CByteArray to store and retrieve unsigned char data Pin
snprani4-Sep-05 23:16
snprani4-Sep-05 23:16 
AnswerRe: How to use CByteArray to store and retrieve unsigned char data Pin
ThatsAlok4-Sep-05 23:50
ThatsAlok4-Sep-05 23:50 
Questionhandwolf@126.com Pin
superhandwolf4-Sep-05 23:05
superhandwolf4-Sep-05 23:05 
AnswerRe: handwolf@126.com Pin
toxcct4-Sep-05 23:15
toxcct4-Sep-05 23:15 
GeneralRe: handwolf@126.com Pin
handwolf824-Sep-05 23:30
handwolf824-Sep-05 23:30 
QuestionRe: handwolf@126.com Pin
toxcct4-Sep-05 23:33
toxcct4-Sep-05 23:33 
AnswerRe: handwolf@126.com Pin
superhandwolf5-Sep-05 1:11
superhandwolf5-Sep-05 1:11 
GeneralRe: handwolf@126.com Pin
superhandwolf5-Sep-05 3:19
superhandwolf5-Sep-05 3:19 
AnswerRe: handwolf@126.com Pin
Gary R. Wheeler5-Sep-05 4:24
Gary R. Wheeler5-Sep-05 4:24 
QuestionHow to properly stop STA thread Pin
ComplexLifeForm4-Sep-05 23:03
ComplexLifeForm4-Sep-05 23:03 
AnswerRe: How to properly stop STA thread Pin
MailtoGops5-Sep-05 4:08
MailtoGops5-Sep-05 4:08 
GeneralRe: How to properly stop STA thread Pin
ComplexLifeForm5-Sep-05 7:06
ComplexLifeForm5-Sep-05 7:06 
Questionproblem at run time window Pin
a_david1234-Sep-05 22:57
a_david1234-Sep-05 22:57 
AnswerRe: problem at run time window Pin
MailtoGops5-Sep-05 4:15
MailtoGops5-Sep-05 4:15 
QuestionCheck file status Pin
Member 11412684-Sep-05 22:53
Member 11412684-Sep-05 22:53 
AnswerRe: Check file status Pin
ThatsAlok4-Sep-05 23:24
ThatsAlok4-Sep-05 23:24 
QuestionSharing data between two DLLs Pin
lata07mahi4-Sep-05 22:14
lata07mahi4-Sep-05 22:14 

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.