Page 1 of 5
which *int* ?
Posted: Sun Aug 09, 2009 10:44 pm
by earlz
If you must have an integer of size 32 bits, how would you code it up?
Re: which *int* ?
Posted: Sun Aug 09, 2009 10:50 pm
by pcmattman
int32_t.
If I wanted an
unsigned integer of 32 bits, uint32_t
.
EDIT: I use these mainly because I'm following
the standard.
Re: which *int* ?
Posted: Sun Aug 09, 2009 11:47 pm
by Solar
uint32_t, because then I don't have to "code it up" but merely include <stdint.h>.
Re: which *int* ?
Posted: Mon Aug 10, 2009 1:56 pm
by gravaera
Actually, I have this thing about using a simple 'unsigned' and nothing else. I mainly use a type:
uarch_t (Unsigned Architecture type) that is nothing more than a typedef unsigned uarch_t.
This means that on a compiler that's 64 bit, I assume it would take a simple unsigned to be a 64 bit integer type. for a specific 'long' I use 'ulong32'.
Code: Select all
#ifndef __POSIX_TYPES_H
#define __POSIX_TYPES_H
typedef unsigned int size_t;
typedef unsigned char uchar8;
typedef unsigned short ushort16;
typedef unsigned long ulong32;
typedef unsigned uarch_t;
typedef struct {unsigned long p1; unsigned long p2;} uqword64;
typedef char schar8;
typedef short sshort16;
typedef long slong32;
typedef signed sarch_t;
typedef struct {long p1; long p2;} sqword64;
#endif
I use the uarch_t almost throughout my source, assuming it will help with portability later. If not, then it doesn't hurt, either. The 's/uqword64' is an artifact from my earlier days when I was still getting into the full swing of OSDev.
Re: which *int* ?
Posted: Mon Aug 10, 2009 3:59 pm
by neon
I both use uint32_t (because of stdint.h) or UINT and DWORD types depending on what I am working with.
Re: which *int* ?
Posted: Mon Aug 10, 2009 5:03 pm
by manonthemoon
@gravaera: I hope you know that "unsigned" is the same exact thing as "unsigned int".
In my kernel I use "byte", "word", and "dword" for the types that must be 8/16/32 bits. But I admit that it's a pretty crappy way to do things.
Re: which *int* ?
Posted: Mon Aug 10, 2009 7:50 pm
by earlz
rofl I just realized. No one voted u32int. Yet we have a huge piece of tutorial code in the wiki using nothing but u32int.. or wait, maybe that was what JamesM used.. I can't remember lol, but yea I forgot about the DWORD and such types that I myself once used..
Re: which *int* ?
Posted: Tue Aug 11, 2009 5:28 pm
by Thor
I use uint32... because that way I don't have to put so many _t's
Re: which *int* ?
Posted: Tue Aug 11, 2009 6:24 pm
by gravaera
@manonthemoon: yea. I just have certain weird paranoia and practices I adhere to while coding that I never drop...
Even if technically they don't hold that much water.
Re: which *int* ?
Posted: Wed Aug 12, 2009 7:18 pm
by xvedejas
I like u32int because the numbers separate the characters... it's more aesthetically pleasing
Re: which *int* ?
Posted: Wed Aug 12, 2009 7:43 pm
by earlz
xvedejas wrote:I like u32int because the numbers separate the characters... it's more aesthetically pleasing
I prefer to say 40$ so that it reads "forty dollars" but it goes against all standards, so everyone would laugh at me for using such a thing... lol
Re: which *int* ?
Posted: Wed Aug 12, 2009 8:22 pm
by AndrewAPrice
earlz wrote:xvedejas wrote:I like u32int because the numbers separate the characters... it's more aesthetically pleasing
I prefer to say 40$ so that it reads "forty dollars" but it goes against all standards, so everyone would laugh at me for using such a thing... lol
So I guess you're a 0000h guy, not a 0x0000 guy when it comes to writing hexadecimal? What if you want to write in octal?
Re: which *int* ?
Posted: Wed Aug 12, 2009 8:44 pm
by earlz
MessiahAndrw wrote:earlz wrote:xvedejas wrote:I like u32int because the numbers separate the characters... it's more aesthetically pleasing
I prefer to say 40$ so that it reads "forty dollars" but it goes against all standards, so everyone would laugh at me for using such a thing... lol
So I guess you're a 0000h guy, not a 0x0000 guy when it comes to writing hexadecimal? What if you want to write in octal?
you missed the point. People should follow such common and in-place standards(which are as easy to follow as these) no matter what their silly personal preference is..
(as in, I forgot the <sarcasm> tag)
Re: which *int* ?
Posted: Wed Sep 09, 2009 9:08 pm
by thepowersgang
Personally I use Uint32 (but when working on 32-bit systems, Uint means the same)
Re: which *int* ?
Posted: Wed Sep 09, 2009 10:00 pm
by Hangin10
I almost always use my own "types.h" which just creates u8, s8, u16, s16, etc.
I know the types are integers, so I don't need "int" or "long" or some other word in the type.
This way there's no space in the type, it's usually less than 4 characters long, and I see the signedness
and length at once (which is all I need).
Now that doesn't mean I would ever typedef float or double to something different (unless you want
f32, f80, f128, ... f60? which I don't find necessary).