which *int* ?
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: which *int* ?
char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long.
Portability is a waste of time for me. I don't plan on it at all.
I'm an x86 freak
Portability is a waste of time for me. I don't plan on it at all.
I'm an x86 freak
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Re: which *int* ?
And then you realize that even C compilers on the x86 can be inconsistent with integer sizes.Troy Martin wrote:char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long.
Portability is a waste of time for me. I don't plan on it at all.
I'm an x86 freak
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: which *int* ?
Okay, then, I'm a GCC-i586 freak. Fixed!
Re: which *int* ?
...in its current version. (Yes, I admit, it is unlikely they'll change it, but...)
This ain't about portability. IMHO, this goes much, much deeper.
You need an integer of exactly 32 bits. If you are the type that will simply check if int or long is good enough and then uses that deserves every bit of pain buggy code ever inflicts on him. And some more.
"int" might be 32 bit, but it does neither guarantee nor say so. "int" says "a whatever-sized integer value, I don't really care". Whereas int32_t says "a 32bit integer, and make it exactly 32 bits because it's important".
And as for using standards vs. rolling your own... sure there might be some advantages in driving on the wrong side of the road (such as, no-one in front of you to slow you down), but in the long run you aren't making friends that way...
Edit: That paragraph above about "saying so" refers to the documentation value of "int32_t" vs. "int", of course.
This ain't about portability. IMHO, this goes much, much deeper.
You need an integer of exactly 32 bits. If you are the type that will simply check if int or long is good enough and then uses that deserves every bit of pain buggy code ever inflicts on him. And some more.
"int" might be 32 bit, but it does neither guarantee nor say so. "int" says "a whatever-sized integer value, I don't really care". Whereas int32_t says "a 32bit integer, and make it exactly 32 bits because it's important".
And as for using standards vs. rolling your own... sure there might be some advantages in driving on the wrong side of the road (such as, no-one in front of you to slow you down), but in the long run you aren't making friends that way...
Edit: That paragraph above about "saying so" refers to the documentation value of "int32_t" vs. "int", of course.
Last edited by Solar on Thu Sep 10, 2009 12:13 pm, edited 1 time in total.
Every good solution is obvious once you've found it.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: which *int* ?
I don't like pain, can I change my vote?
Thanks, Solar, for that. I think I'm going to start #including <stdint.h> from now on and using whatevar's defined in thar.
Thanks, Solar, for that. I think I'm going to start #including <stdint.h> from now on and using whatevar's defined in thar.
- spere
- Posts: 6
- Joined: Mon Sep 07, 2009 1:51 pm
- Location: Where ever my CBR600rr takes me..
- Contact:
Re: which *int* ?
Being a C# developer, it would be
uint
or
System.UInt32
didn't expect that one, did you?
Then again in masm i would use
VarName dw
uint
or
System.UInt32
didn't expect that one, did you?
Then again in masm i would use
VarName dw
mov ah, 4ch
int 21h
int 21h
Re: which *int* ?
ugh.. I hate C# in that respect.. Uint32. Just look at it. What an ugly name. It's inconsistent with every other language, and itself(where core types are lower case, such as int, float, object, string) Microsoft should've thought a little harder about that...spere wrote:Being a C# developer, it would be
uint
or
System.UInt32
didn't expect that one, did you?
Then again in masm i would use
VarName dw
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: which *int* ?
If you think about it, why do compilers even have the types "int", "short", etc. anymore? It's not any faster, and it's not any simpler. Plus, I rarely have a circumstance where I don't care exactly how many bits I can use in an integer. If you want to make any remotely portable code, you're going to end up using int32_t and int16_t, or at least intmax_t, and that requires including an extra header.Solar wrote:...in its current version. (Yes, I admit, it is unlikely they'll change it, but...)
This ain't about portability. IMHO, this goes much, much deeper.
You need an integer of exactly 32 bits. If you are the type that will simply check if int or long is good enough and then uses that deserves every bit of pain buggy code ever inflicts on him. And some more.
"int" might be 32 bit, but it does neither guarantee nor say so. "int" says "a whatever-sized integer value, I don't really care". Whereas int32_t says "a 32bit integer, and make it exactly 32 bits because it's important".
And as for using standards vs. rolling your own... sure there might be some advantages in driving on the wrong side of the road (such as, no-one in front of you to slow you down), but in the long run you aren't making friends that way...
Edit: That paragraph above about "saying so" refers to the documentation value of "int32_t" vs. "int", of course.
Why doesn't the C standard simply force the compiler to have those types as builtins, instead of the normal integer types? Then people would write correct code *from the beginning*, without the argument of laziness for using normal types.
If I ever write a C compiler (and I'm planning to... eventually), I would more than happily throw "int" out the window.
Re: which *int* ?
NickJohnson wrote:If you think about it, why do compilers even have the types "int", "short", etc. anymore? It's not any faster, and it's not any simpler. Plus, I rarely have a circumstance where I don't care exactly how many bits I can use in an integer. If you want to make any remotely portable code, you're going to end up using int32_t and int16_t, or at least intmax_t, and that requires including an extra header.Solar wrote:...in its current version. (Yes, I admit, it is unlikely they'll change it, but...)
This ain't about portability. IMHO, this goes much, much deeper.
You need an integer of exactly 32 bits. If you are the type that will simply check if int or long is good enough and then uses that deserves every bit of pain buggy code ever inflicts on him. And some more.
"int" might be 32 bit, but it does neither guarantee nor say so. "int" says "a whatever-sized integer value, I don't really care". Whereas int32_t says "a 32bit integer, and make it exactly 32 bits because it's important".
And as for using standards vs. rolling your own... sure there might be some advantages in driving on the wrong side of the road (such as, no-one in front of you to slow you down), but in the long run you aren't making friends that way...
Edit: That paragraph above about "saying so" refers to the documentation value of "int32_t" vs. "int", of course.
Why doesn't the C standard simply force the compiler to have those types as builtins, instead of the normal integer types? Then people would write correct code *from the beginning*, without the argument of laziness for using normal types.
If I ever write a C compiler (and I'm planning to... eventually), I would more than happily throw "int" out the window.
This is very true.. Why do they have int?
Well, I have one reason, is the speed for trivial small things like cycling through a loop that should never grow to more than 200. For it, you would of course want the fastest integer possible, which presumably is int. And to cycle through such a list should not involve a design decision as to if your going to limit this to 16 bits or 32 bits or 64 bits..
I think the int32_fast_t or whatever they are called types need to be utilized more often(possibly by a better and shorter naming scheme)
Other than the speed and memory issue and the pain of typing intptr_t, I have no problem with int forever being gone as a generic unknown type of death.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: which *int* ?
Cause generally, programmers that don't have a f**king clue about 32-bit integers versus 16-bit integers versus 64-bit ones etc. just use int in all their code cause "it's easier". Well, if I were a programmer that didn't need to deal with low-level stuffs like uint32_t and friends I'd just slap int everywhere without thinking about the bytes I could be saving by using short or char or the appropriate ?int*_t type.earlz wrote:This is very true.. Why do they have int?
Re: which *int* ?
Well well... maybe programmers should be made more aware..Troy Martin wrote:Cause generally, programmers that don't have a f**king clue about 32-bit integers versus 16-bit integers versus 64-bit ones etc. just use int in all their code cause "it's easier". Well, if I were a programmer that didn't need to deal with low-level stuffs like uint32_t and friends I'd just slap int everywhere without thinking about the bytes I could be saving by using short or char or the appropriate ?int*_t type.earlz wrote:This is very true.. Why do they have int?
and when people make something like
Code: Select all
char *longstring;
...
int i;
for(i=0;i<strlen(longstring);i++){
putc(longstring[i]);
}
This could be much less of a problem though if we could safely assume sizeof(int)==sizeof(void*)
-
- 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* ?
Any decent compiler (MSVC's, and GCC, in the least) will throw a warning about the conversion from unsigned to signed (strlen returns a size_t). So your example is invalid, because programmers are made aware that their code is faulty.Code: Select all
for(i=0;i<strlen(longstring);i++){ putc(longstring[i]); }
Actually, the reason why we "still have" int is for backwards compatibility (with the current standard, too). If you'd like to make a variant of C that doesn't have int, short, etc... - go ahead. But it's non-standard C. Just use stdint.h, which was introduced in C99.Cause generally, programmers that don't have a f**king clue about 32-bit integers versus 16-bit integers versus 64-bit ones etc. just use int in all their code cause "it's easier"
The names of each types worked fine when C was first created, because you would be targeting a specific hardware platform with your code. Once portability became a concern steps were taken to make it possible to write portable code without breaking old code.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: which *int* ?
Looks like what we need to do is tell the world that int and friends are deprecated and we should all use the wonders of platform independent variable types.
Re: which *int* ?
I still want to implement a language where you doTroy Martin wrote:Looks like what we need to do is tell the world that int and friends are deprecated and we should all use the wonders of platform independent variable types.
Code: Select all
int:8 byte;
int:16 word;
int:21 wtf;
edit:
Anyone know how to specify a 16bit number in C where int and long are 64 bits? (presumably short would be 32)
And any hope of getting a uint128_t anytime soon?
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: which *int* ?
Oh come on earlz, read through the topic again! Use uint16_t!earlz wrote:Anyone know how to specify a 16bit number in C where int and long are 64 bits? (presumably short would be 32)
I think it's an unofficial extension on some compilers (likely MSVC) but as far as I know it's nonstandard. Might be standard in C1x, but as of the latest draft, I couldn't find anything about it. Googling it displays something about GCC 3.1 on the PowerPC having uint128_t.And any hope of getting a uint128_t anytime soon?