which *int* ?
which *int* ?
If you must have an integer of size 32 bits, how would you code it up?
-
- 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* ?
int32_t.
If I wanted an unsigned integer of 32 bits, uint32_t .
EDIT: I use these mainly because I'm following the standard.
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* ?
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.
- gravaera
- 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* ?
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'.
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.
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
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
Re: which *int* ?
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();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
-
- Member
- Posts: 65
- Joined: Sat Jul 04, 2009 9:39 pm
Re: which *int* ?
@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.
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* ?
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* ?
I use uint32... because that way I don't have to put so many _t's
Vancouver Canucks fan for life
- gravaera
- 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* ?
@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.
Re: which *int* ?
I like u32int because the numbers separate the characters... it's more aesthetically pleasing
Valix is an experiment in an interpreted userspace with object-oriented and functional design patterns. Developers needed! Join #valix on irc.freenode.net
Re: which *int* ?
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... lolxvedejas wrote:I like u32int because the numbers separate the characters... it's more aesthetically pleasing
- AndrewAPrice
- Member
- Posts: 2299
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
Re: which *int* ?
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?earlz wrote: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... lolxvedejas wrote:I like u32int because the numbers separate the characters... it's more aesthetically pleasing
My OS is Perception.
Re: which *int* ?
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..MessiahAndrw wrote: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?earlz wrote: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... lolxvedejas wrote:I like u32int because the numbers separate the characters... it's more aesthetically pleasing
(as in, I forgot the <sarcasm> tag)
- thepowersgang
- Member
- Posts: 734
- Joined: Tue Dec 25, 2007 6:03 am
- Libera.chat IRC: thePowersGang
- Location: Perth, Western Australia
- Contact:
Re: which *int* ?
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
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Re: which *int* ?
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).
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).