which *int* ?

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.

If you must have an unsigned integer of size 32 bits, how would you code it up?

u32int
4
6%
uint32_t
30
42%
u32int_t
0
No votes
uint32
12
17%
unsigned int (I don't care about portability)
8
11%
something else
17
24%
 
Total votes: 71

earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

which *int* ?

Post by earlz »

If you must have an integer of size 32 bits, how would you code it up?
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: which *int* ?

Post by pcmattman »

int32_t.

If I wanted an unsigned integer of 32 bits, uint32_t :mrgreen: .

EDIT: I use these mainly because I'm following the standard.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: which *int* ?

Post by Solar »

uint32_t, because then I don't have to "code it up" but merely include <stdint.h>.
Every good solution is obvious once you've found it.
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: which *int* ?

Post 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. :lol:
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: which *int* ?

Post by neon »

I both use uint32_t (because of stdint.h) or UINT and DWORD types depending on what I am working with.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
manonthemoon
Member
Member
Posts: 65
Joined: Sat Jul 04, 2009 9:39 pm

Re: which *int* ?

Post 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.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: which *int* ?

Post 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..
User avatar
Thor
Member
Member
Posts: 51
Joined: Mon Jul 06, 2009 12:55 am
Location: Kamloops, BC, Canada

Re: which *int* ?

Post by Thor »

I use uint32... because that way I don't have to put so many _t's :P
Vancouver Canucks fan for life
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: which *int* ?

Post 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.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
xvedejas
Member
Member
Posts: 168
Joined: Thu Jun 04, 2009 5:01 pm

Re: which *int* ?

Post by xvedejas »

I like u32int because the numbers separate the characters... it's more aesthetically pleasing :)
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: which *int* ?

Post 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
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: which *int* ?

Post 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?
My OS is Perception.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: which *int* ?

Post 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)
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: which *int* ?

Post by thepowersgang »

Personally I use Uint32 (but when working on 32-bit systems, Uint means the same)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Hangin10
Member
Member
Posts: 162
Joined: Wed Feb 27, 2008 12:40 am

Re: which *int* ?

Post 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).

:)
Post Reply