Re: Promoting unsigned long int to long int
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: 30 Jun 2008 09:43:50 -0700
pereges <Broli00@xxxxxxxxx> writes:
On Jun 30, 8:49 pm, Keith Thompson <ks...@xxxxxxx> wrote:
These types already have perfectly good names already. Why give them
new ones?
No purpose really. Just that in some of my functions, there are too
many parameters already and the whole thing doesn't fit in single
line.
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 you must rename them for some reason, use typedefs, not macros.
ok
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- Follow-Ups:
- Re: Promoting unsigned long int to long int
- From: pereges
- 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
- Promoting unsigned long int to long int
- Prev by Date: Re: OOP
- 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
|