Click here to Skip to main content
15,912,977 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Fairly basic pointer/array question Pin
cp987621-Aug-07 16:54
cp987621-Aug-07 16:54 
GeneralRe: Fairly basic pointer/array question Pin
MALDATA21-Aug-07 18:17
MALDATA21-Aug-07 18:17 
GeneralRe: Fairly basic pointer/array question Pin
cp987621-Aug-07 19:13
cp987621-Aug-07 19:13 
GeneralRe: Fairly basic pointer/array question Pin
Nelek21-Aug-07 20:14
protectorNelek21-Aug-07 20:14 
GeneralRe: Fairly basic pointer/array question Pin
cp987621-Aug-07 21:12
cp987621-Aug-07 21:12 
GeneralRe: Fairly basic pointer/array question Pin
Nelek22-Aug-07 1:20
protectorNelek22-Aug-07 1:20 
GeneralRe: Fairly basic pointer/array question Pin
MALDATA22-Aug-07 4:18
MALDATA22-Aug-07 4:18 
GeneralRe: Fairly basic pointer/array question Pin
Nelek22-Aug-07 4:55
protectorNelek22-Aug-07 4:55 
node* out = new node*[3];

Should it not be...

node* out[3] = new node* [3]; ???

And with the sizeof... im not sure about. I had problems with it too.
I made:

(THIS IS FALSE)

DWORD Header [9];

void CTool::WriteHeader (CFile* file)
{	Header[0] = MAGIC;
	Header[1] = VERSION;
	Header[2] = CalculateCodeLarge ();
	Header[3] = CalculateDataLarge ();
	Header[4] = CalculateNumberOfElements ();
	Header[5] = RESERVE;
	Header[6] = (DWORD) m_cmlSet1.GetCount ();
	Header[7] = (DWORD) m_cmlSet2.GetCount ();
	Header[8] = PCRES;

	file->Write (&Header[0], sizeof (Header));

	return;
}


and I solved it with:
(THIS IS WORKING GOOD)

DWORD Header [9];

void CTool::WriteHeader (CFile* file)
{	Header[0] = MAGIC;
	Header[1] = VERSION;
	Header[2] = CalculateCodeLarge ();
	Header[3] = CalculateDataLarge ();
	Header[4] = CalculateNumberOfElements ();
	Header[5] = RESERVE;
	Header[6] = (DWORD) m_cmlSet1.GetCount ();
	Header[7] = (DWORD) m_cmlSet2.GetCount ();
	Header[8] = PCRES;

	DWORD* pHeadBuf;
	pHeadBuf = &Header[0];
	file->Write (pHeadBuf, sizeof (Header));

	return;
}


I think is because a Pointer has a fixed longitude for the sizeof, but your object does not. So if you increment in the size of a pointer, you will may have not enough place to the datas contained in your object, or maybe too much place. Or just looking with a completely false adress, what would made you have garbage.

Actually you should increment the pointer in one adress to point your next element, but the size you are moving is actually the size of your object.

I hope that I have explained myself not meaningless (im not englishspeaker) and that it helps you (im not such a good programmer as many others in this site)



Greetings.

--------
M.D.V.

If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?

GeneralRe: Fairly basic pointer/array question Pin
MALDATA22-Aug-07 8:39
MALDATA22-Aug-07 8:39 
GeneralRe: Fairly basic pointer/array question Pin
Nelek22-Aug-07 20:01
protectorNelek22-Aug-07 20:01 
GeneralRe: Fairly basic pointer/array question Pin
cp987622-Aug-07 20:40
cp987622-Aug-07 20:40 
QuestionCreateDirectoryA can not be resolved Pin
George_George21-Aug-07 16:27
George_George21-Aug-07 16:27 
AnswerRe: CreateDirectoryA can not be resolved [modified] Pin
Paresh Chitte21-Aug-07 18:36
Paresh Chitte21-Aug-07 18:36 
GeneralRe: CreateDirectoryA can not be resolved Pin
George_George21-Aug-07 20:51
George_George21-Aug-07 20:51 
GeneralRe: CreateDirectoryA can not be resolved Pin
Paresh Chitte21-Aug-07 22:05
Paresh Chitte21-Aug-07 22:05 
GeneralRe: CreateDirectoryA can not be resolved Pin
George_George21-Aug-07 22:23
George_George21-Aug-07 22:23 
AnswerRe: CreateDirectoryA can not be resolved Pin
David Crow22-Aug-07 2:30
David Crow22-Aug-07 2:30 
GeneralRe: CreateDirectoryA can not be resolved Pin
George_George22-Aug-07 3:16
George_George22-Aug-07 3:16 
QuestionEncoder Pin
celllllllll21-Aug-07 12:08
celllllllll21-Aug-07 12:08 
QuestionRe: Encoder Pin
celllllllll21-Aug-07 12:27
celllllllll21-Aug-07 12:27 
AnswerRe: Encoder Pin
cp987621-Aug-07 13:29
cp987621-Aug-07 13:29 
AnswerRe: Encoder Pin
El Corazon21-Aug-07 13:48
El Corazon21-Aug-07 13:48 
GeneralRe: Encoder Pin
celllllllll21-Aug-07 14:33
celllllllll21-Aug-07 14:33 
GeneralRe: Encoder Pin
El Corazon21-Aug-07 15:03
El Corazon21-Aug-07 15:03 
AnswerRe: Encoder Pin
Stephen Hewitt21-Aug-07 14:35
Stephen Hewitt21-Aug-07 14:35 

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.