Re: Promoting unsigned long int to long int
- From: pereges <Broli00@xxxxxxxxx>
- Date: Mon, 30 Jun 2008 09:55:53 -0700 (PDT)
On Jun 30, 9:43 pm, Keith Thompson <ks...@xxxxxxx> wrote:
So write it on multiple lines.
Given:
#define ulong unsigned long int
#define uchar unsigned char
or, preferably:
typedef unsigned long int ulong;
typedef unsigned char uchar;
If I'm reading your code and see a reference to "ulong", I can't
understand what it means until I've confirmed that "ulong" means
"unsigned long int" (which I'd probably write as "unsigned long").
And I have to wonder whether you might some day change the definition
so "ulong" means something else.
If you drop the definition of "ulong" and just write "unsigned long"
directly, I don't have to wonder; your code will be clearer.
Now if you want a typedef whose name says something about how you're
using the type, rather than how it's define, that's a different
matter.
You use "ulong" for array indices; it would make more sense to use
size_t.
You use "uchar" for a parameter that can only have the value 0, 1, or
2. I'd use int. Using unsigned char might save some space, but it's
just as likely to cost you in code size, since the compiler has to
generate code to expand the 1-byte value into a word before it can
operate on it, and to shrink it back down to 1 byte before storing it.
You also make the reader wonder whether there's some fundamental
reason for this value to fit into a byte (there isn't). If you had an
array of these things, it would make sense to use a smaller type.
Since it's just a single parameter, using int is fine.
If I had to store 80-90 of structures and each had a member say
'axis'. How much of a difference would using a unsigned char over int
would make (for that member) ? For my program, space as well as
performance are important.
.
- Follow-Ups:
- Re: Promoting unsigned long int to long int
- From: santosh
- Re: Promoting unsigned long int to long int
- From: pete
- Re: Promoting unsigned long int to long int
- From: Keith Thompson
- Re: Promoting unsigned long int to long int
- References:
- Promoting unsigned long int to long int
- From: pereges
- Re: Promoting unsigned long int to long int
- From: Keith Thompson
- Re: Promoting unsigned long int to long int
- From: pereges
- Re: Promoting unsigned long int to long int
- From: Keith Thompson
- Promoting unsigned long int to long int
- Prev by Date: Re: problem passing pointer array
- Next by Date: Re: Promoting unsigned long int to long int
- Previous by thread: Re: Promoting unsigned long int to long int
- Next by thread: Re: Promoting unsigned long int to long int
- Index(es):
Relevant Pages
|