Click here to Skip to main content
15,890,973 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to set Background color, & Icon of CButton & How to use CBitmapButton Pin
pankaj293831-Feb-11 19:08
pankaj293831-Feb-11 19:08 
AnswerRe: How to set Background color, & Icon of CButton & How to use CBitmapButton Pin
Malli_S1-Feb-11 19:56
Malli_S1-Feb-11 19:56 
AnswerRe: How to set Background color, & Icon of CButton & How to use CBitmapButton [modified] Pin
_AnsHUMAN_ 1-Feb-11 19:57
_AnsHUMAN_ 1-Feb-11 19:57 
Questionhow to do function like cout Pin
KARFER1-Feb-11 6:10
KARFER1-Feb-11 6:10 
AnswerRe: how to do function like cout Pin
Richard MacCutchan1-Feb-11 6:16
mveRichard MacCutchan1-Feb-11 6:16 
AnswerRe: how to do function like cout Pin
«_Superman_»1-Feb-11 7:48
professional«_Superman_»1-Feb-11 7:48 
AnswerRe: how to do function like cout Pin
Stefan_Lang1-Feb-11 23:18
Stefan_Lang1-Feb-11 23:18 
QuestionRelease VS Debug compiles Pin
Khan Shere1-Feb-11 3:47
Khan Shere1-Feb-11 3:47 
Hello, I've got this little program in Visual Studio C++ 2008; console application.
When I run it into debug mode, it works perfectly. If I compile for release, the instructions:

<br />
<br />
while(nVector[nPos + 1] == nVector[nPos] + 1)<br />
<br />


or

<br />
<br />
for(;nVector[nPos + 1] == nVector[nPos] + 1;)<br />
<br />


are not working...
The only one that works for both debug and release is:

<br />
<br />
		nPos--;<br />
<br />
		do<br />
		{<br />
			nPos++;<br />
		}<br />
		while(nVector[nPos + 1] == nVector[nPos] + 1);<br />
<br />


Here is the whole code:

<br />
<br />
// Bogosort.cpp : Defines the entry point for the console application.<br />
//<br />
<br />
#include "stdafx.h"<br />
<br />
#define SIZE_VECTOR		10<br />
#define _DEBUG_WHILE_USE<br />
<br />
<br />
unsigned int random(const unsigned int &uMin, const unsigned int &uMax);<br />
void printVector(unsigned int nVector[]);<br />
void swap(unsigned int &uFirst, unsigned int &uSecond);<br />
void randomize(unsigned int nVector[], const int &nPos);<br />
<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
	unsigned int nVector[SIZE_VECTOR];<br />
	unsigned int nStep = 0;<br />
	int nPos = 0;<br />
<br />
	for(int i = 0; i < SIZE_VECTOR; i++)<br />
	{<br />
		nVector[i] = i;<br />
	}<br />
<br />
	printf("Start...\r\n\r\n");<br />
<br />
	while(nPos < SIZE_VECTOR - 1)<br />
	{<br />
		randomize(nVector, nPos + 1);<br />
		printVector(nVector);<br />
		nStep++;<br />
<br />
#ifdef _DEBUG<br />
#ifdef _DEBUG_WHILE_USE<br />
		while(nVector[nPos + 1] == nVector[nPos] + 1)<br />
		{<br />
			nPos++;<br />
		}<br />
#else // _DEBUG_WHILE_USE<br />
		for(;nVector[nPos + 1] == nVector[nPos] + 1;)<br />
			nPos++;<br />
#endif // _DEBUG_WHILE_USE<br />
#else // _DEBUG<br />
		nPos--;<br />
<br />
		do<br />
		{<br />
			nPos++;<br />
		}<br />
		while(nVector[nPos + 1] == nVector[nPos] + 1);<br />
#endif // _DEBUG<br />
	}<br />
<br />
	printf("\r\nSteps: %d.\r\n\r\n", nStep);<br />
	return 0;<br />
}<br />
<br />
unsigned int random(const unsigned int &uMin, const unsigned int &uMax) // [uMin, uMax]<br />
{<br />
	unsigned int uRand = 0;<br />
<br />
	if((uMin <= uMax) && (rand_s(&uRand) == 0))<br />
	{<br />
		double dDiv = (double)uRand / (double)UINT_MAX;<br />
		double dMul = dDiv * (double)(uMax - uMin + 1);<br />
		uRand = (unsigned int)(dMul + uMin);<br />
	}<br />
<br />
	return uRand;<br />
}<br />
<br />
void printVector(unsigned int nVector[])<br />
{<br />
	for(int i = 0; i < SIZE_VECTOR; i++)<br />
	{<br />
		printf("%2d%s", nVector[i], (i == SIZE_VECTOR - 1) ? ".\r\n" : ", ");<br />
	}<br />
}<br />
<br />
void swap(unsigned int &uFirst, unsigned int &uSecond)<br />
{<br />
	unsigned int uTemp = uFirst;<br />
	uFirst = uSecond;<br />
	uSecond = uTemp;<br />
}<br />
<br />
void randomize(unsigned int nVector[], const int &nPos)<br />
{<br />
	for(int i = nPos; i < SIZE_VECTOR - 1; i++)<br />
	{<br />
		swap(nVector[nPos], nVector[random(i, SIZE_VECTOR - 1)]);<br />
	}<br />
}<br />
<br />


with

<br />
<br />
#define _CRT_RAND_S<br />
<br />
#include <stdlib.h><br />
<br />


in stdafx.h

Does anyone have any idea why this is happening?
Thank you!
AnswerRe: Release VS Debug compiles Pin
Chris Losinger1-Feb-11 3:51
professionalChris Losinger1-Feb-11 3:51 
GeneralRe: Release VS Debug compiles Pin
Khan Shere1-Feb-11 3:55
Khan Shere1-Feb-11 3:55 
GeneralRe: Release VS Debug compiles Pin
Richard MacCutchan1-Feb-11 4:21
mveRichard MacCutchan1-Feb-11 4:21 
GeneralRe: Release VS Debug compiles Pin
Khan Shere1-Feb-11 5:01
Khan Shere1-Feb-11 5:01 
GeneralRe: Release VS Debug compiles Pin
Richard MacCutchan1-Feb-11 6:13
mveRichard MacCutchan1-Feb-11 6:13 
AnswerRe: Release VS Debug compiles Pin
Andrew Brock1-Feb-11 4:50
Andrew Brock1-Feb-11 4:50 
GeneralRe: Release VS Debug compiles [modified] Pin
Aescleal1-Feb-11 7:58
Aescleal1-Feb-11 7:58 
AnswerRe: Release VS Debug compiles Pin
User 74293381-Feb-11 10:02
professionalUser 74293381-Feb-11 10:02 
GeneralRe: Release VS Debug compiles Pin
Khan Shere1-Feb-11 20:57
Khan Shere1-Feb-11 20:57 
Questionuse the member pointer via a Get function and allocate memory outside, not clear why in this way Pin
George Nistor1-Feb-11 1:36
George Nistor1-Feb-11 1:36 
AnswerRe: use the member pointer via a Get function and allocate memory outside, not clear why in this way Pin
Niklas L1-Feb-11 1:49
Niklas L1-Feb-11 1:49 
AnswerRe: use the member pointer via a Get function and allocate memory outside, not clear why in this way Pin
Andrew Brock1-Feb-11 2:17
Andrew Brock1-Feb-11 2:17 
Questionerror C2011: 'CMemDC' : 'class' type redefinition Pin
VCProgrammer31-Jan-11 21:25
VCProgrammer31-Jan-11 21:25 
AnswerRe: error C2011: 'CMemDC' : 'class' type redefinition Pin
Cool_Dev31-Jan-11 21:38
Cool_Dev31-Jan-11 21:38 
GeneralRe: error C2011: 'CMemDC' : 'class' type redefinition Pin
VCProgrammer31-Jan-11 21:41
VCProgrammer31-Jan-11 21:41 
GeneralRe: error C2011: 'CMemDC' : 'class' type redefinition Pin
PJ Arends1-Feb-11 18:14
professionalPJ Arends1-Feb-11 18:14 
GeneralRe: error C2011: 'CMemDC' : 'class' type redefinition Pin
Malli_S1-Feb-11 20:40
Malli_S1-Feb-11 20:40 

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.