Skip to main content
gamedev.net
🔒 Locked

Strange C problem

Started by Kranman 4 replies 700+ views
Original Post
Kranman
Kranman
When I execute this code, I get 4 byte numbers out! Console->Echo() outputs text to the console.
unsigned int *Data = new unsigned int[num];
fread(Data, 2, num, file)
Console->Echo("Data[0] = %x", Data[0]);
 
This doesnt seem possible - and the extra bytes are what should have been the next element''s data, so it''s reading 4 bytes into it... A memory problem?
jenova
jenova
okay: i am assuming a lot here (which could make an ass out of you and me).

assuming: Windows, Intel x86, VisualStudio 4.0 to 6.0, etc.

unsigned int = 32 bits or 4 bytes.
unsigned long = 32 bits or 4 bytes.
unsigned short = 16 bits or 2 bytes.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
jenova
jenova
Null and Void: 3 seconds. u bastard. j/k. nice answer.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Kranman
Kranman
Hm.. I remember reading in some (apparently old) docs that short was the same length as int. How mislead I was...

Thanks.
Null and Void
Null and Void
quote:
Original post by Kranman
Hm.. I remember reading in some (apparently old) docs that short was the same length as int. How mislead I was...

They weren''t lying, they were simply refering to the common 16bit systems and compilers. The only rule for the sizes of integer data types in C is: short <= int <= long.

[Resist Windows XP''s Invasive Production Activation Technology!]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.