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:

Re: which *int* ?

Post by earlz »

NickJohnson wrote:
earlz wrote:
fronty wrote:When programming with C# you don't have to use System.Uint32 or Uint32 if you prefer uint. Int32 ^ int, Uint32 ^ uint, Int64 ^ long, and so on. And don't say that it's bad that those shorter names don't tell the actual width of variable, because when you program C#, you always know that your int is 32 bits wide. C# standard says that int represents 32-bit integral value. There are no other possibilities.
I've always hated microsofts decision to make 64bit programming *look* like 32bit programming.. it just ends up in 3 or 4 years, when 64bit arithmetic is slightly faster than 32bit arithmetic, Windows will be *even* slower than other OSs
Except that then they could just have the types actually be 64 bit, and things would act exactly the same, except for the memory usage. Of course, the entire system would have to be recompiled to update the library interfaces...
You can't just change a specification.

If they suddenly make .NET int's 64bit, I bet money it'll break at least 10 "common" applications
User avatar
spere
Posts: 6
Joined: Mon Sep 07, 2009 1:51 pm
Location: Where ever my CBR600rr takes me..
Contact:

Re: which *int* ?

Post by spere »

earlz wrote:If they suddenly make .NET int's 64bit, I bet money it'll break at least 10 "common" applications
This was the bit I wasn't clear about too, but apparenlty when they update the C# compilers, all ints will use 64 bits of space on a 64 bit machine instead of the normal 32. Now that going to break existing code ..... or may be not? :|
Looks like i've got some reading up to do
mov ah, 4ch
int 21h
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: which *int* ?

Post by ru2aqare »

spere wrote:
earlz wrote:If they suddenly make .NET int's 64bit, I bet money it'll break at least 10 "common" applications
They wont. It is defined in the CLR standard (or some other related standard for that matter) that Int32 is 32 bits wide, Int64 is 64 bits wide. Noone can change that.
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 »

I'm surprised .Net didn't opt for an inbuilt arbitrary integer size, since it is used for desktop applications and what-not.

There is a System.Decimal that is a "1-bit sign, a 96-bit integer number, and a scaling factor used to divide the 96-bit integer and specify what portion of it is a decimal fraction. The scaling factor is implicitly the number 10, raised to an exponent ranging from 0 to 28" giving the range ((-2^-96 to 2^-96) / 10^(0 to 28)).
My OS is Perception.
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: which *int* ?

Post by Owen »

It's a different matter for languages like Java and C# to fix "Int" to a size compared to C++. For a start, you're not ([ever {Java} | regularly {C#}]) dealing with pointers.

Also, with 64-bit longs, they happen to look like LP64 programming...
User avatar
Masterkiller
Member
Member
Posts: 153
Joined: Sat May 05, 2007 6:20 pm

Re: which *int* ?

Post by Masterkiller »

unsigned __int32 :wink: (still I am windows user...)
ALCA OS: Project temporarity suspended!
Current state: real-mode kernel-FS reader...
smeezekitty
Member
Member
Posts: 50
Joined: Sat Mar 21, 2009 9:42 pm

Re: which *int* ?

Post by smeezekitty »

unsigned long because i am in real mode
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: which *int* ?

Post by Solar »

What has one to do with the other? I doubt you understood the question...
Every good solution is obvious once you've found it.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: which *int* ?

Post by neon »

unsigned long because i am in real mode
C data types and the current processor mode has nothing to do with each other.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
smeezekitty
Member
Member
Posts: 50
Joined: Sat Mar 21, 2009 9:42 pm

Re: which *int* ?

Post by smeezekitty »

16 bit means int = 16bit
32bit means int = 32bit
so in 16bit you use long to get 32 bits
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: which *int* ?

Post by neon »

Data type size is irrelevant to the processor mode. The size of the data types depend on the generated code from the compiler, not what the processor mode is in.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
smeezekitty
Member
Member
Posts: 50
Joined: Sat Mar 21, 2009 9:42 pm

Re: which *int* ?

Post by smeezekitty »

i know.
i am using Turbo C++ that generates real mode code and uses 16 bit data types.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: which *int* ?

Post by Brynet-Inc »

smeezekitty wrote:16 bit means int = 16bit
32bit means int = 32bit
so in 16bit you use long to get 32 bits
Seriously? this is specific to the compiler.. for example, very few 64-bit C compilers have 'int' as a 64-bit type.

As has been mentioned by others, please read topics before posting.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: which *int* ?

Post by Solar »

smeezekitty wrote:i am using Turbo C++ that generates real mode code and uses 16 bit data types.
And that might be handled different by other compilers, and you never know when you might have to change (or update...) compilers.

Thus, people got the idea to use a typedef to define a type that is known to be of a certain width for the current compiler, and use that type consistently wherever width matters.

The C99 standard uses int32_t for this matter. 55 out of 62 voters use this, or some other define. 7 voted they don't use a define, which is OK in a way. But your comment showed that you are unaware of the whole issue, which does not reflect well on your overall experience with the language.
Every good solution is obvious once you've found it.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: which *int* ?

Post by qw »

Solar wrote:
smeezekitty wrote:i am using Turbo C++ that generates real mode code and uses 16 bit data types.
And that might be handled different by other compilers, and you never know when you might have to change (or update...) compilers.
Come on guys, is there a single C compiler in the world that produces 16 bits real mode code and does not define long as 32 bits? Smeezekitty apparently doesn't care about scalability or portability, but IMHO that's exactly the point of this topic.
Post Reply