Need some help converting to byte(s)

LeetViet

Platinum Member
Mar 6, 2003
2,411
0
76
1 long = ?? byte(s)
1 doubleword = ?? byte(s)
1 quadword = ?? byte(s)

1 float = 4 bytes right?

Am I to assume doubleword = DWORD?
 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
Originally posted by: kamper
what language are you talking about?

I thought it was determined by the architecture rather than the programming language...
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Assuming C:

The size of char, int, and long afaik have no size guarantees, other than int being >= char and long being >= int.

The size of a float is probably even less safe to assume.

A word is 32 bits on a 32-bit machine, 64 on a 64, etc. right?

DWORD is some windows thing, isn't it? If you're on windows, you can assume it's a 32-bit pc. long is 32 bits, int 32, char 8. (right? too lazy to look) Never looked at what float is, but you can figure it out easily with sizeof.

Generally IMO it's bad practice to depend on things being certain sizes like this, at least to some extent. You can pretty safely assume chars are 8 bits, but you shouldn't assume that int is exactly 32 or float is exactly whatever.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
You should learn to use Books Online, or msdn.microsoft.com if you haven't installed the online docs. Learning to Read The Friendly Manual is an essential skill for an aspiring developer.
 

LeetViet

Platinum Member
Mar 6, 2003
2,411
0
76
C++, Windows

Originally posted by: DaveSimmons
You should learn to use Books Online, or msdn.microsoft.com if you haven't installed the online docs. Learning to Read The Friendly Manual is an essential skill for an aspiring developer.

Thanks
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Not trying to be cruel about it, I've been writing VC++ / MFC code for 8 years now and I still often need to look up Win32 API and C++ runtime functions I haven't used recently (sometime not in a couple of years) or ones I haven't needed before. There's no shame in lacking a photographic memory :)

If you're just messing around, waiting for a newsgroup / forum response is fine, but at work I usually need to figure it out immediately so I can solve that problem and move on to the next one.
 

LeetViet

Platinum Member
Mar 6, 2003
2,411
0
76
I haven't had much luck of understanding the stuff I look up...yet.

If I can't assume sizes, are there ways to determine when it's a long/float/dword/qword and an example of what size that one would be?
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
for something like malloc() or reading a binary file, you can use sizeof() but that size will be specific to the platform (intel/x86, x86-64, Sun Sprac, etc.) so you have to jump through more hoops if you need to read or write specific byte sizes.

Some cross-platform code uses #ifdef to define something like MYINT32 based on the platform, where it's a long in x86 and maybe something else on a Sparc or PowerPC. That code also has to juggle PowerPC storing the bytes of an int in the opposite order of an intel/x86.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: igowerf
Originally posted by: kamper
what language are you talking about?

I thought it was determined by the architecture rather than the programming language...

Not always. Java makes architecture-independent guarantees about the size of it's primitive types. (I know he couldn't have been talking about java though; but in order to direct him to the appropriate sizeof operator syntax peeps have to know what language.)