Re: My current dummy_hcd queue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/16/2011 04:24 PM, Alan Stern wrote:
What is the problem with u32? It is a shortcut for unsigned int.

No, it isn't.  The fact that on all current systems it happens to be
the same is merely a coincidence.  You can just as logically claim that
"Obama" is a shortcut for "The last name of the U.S. president".
Right now they happen to be the same.  In a few years they won't.

The intention behind the words is at least as important (to a human
reader, if not to a computer) as the literal meaning of the words.  The
intention behind "unsigned int" is "an unsigned integer of whatever
size the CPU handles most conveniently", whereas the intention behind
"u32" is "an unsigned integer of 32 bits".  These are not the same
thing.

I see where you go with this.

So you are saying that using an int or unsigned is okay but u32 confuses
people beacuase a 32bit value is expected while the former provides the
exact same data type?

That's right.  When I first read your code I thought: "Why did he
specify u32?  He must have some particular reason for requiring exactly
32 bits rather than whatever size the compiler decides on.  What could
that reason be?"  This is very distracting; it interferes with
understanding what's really going on.

Furthermore, my programming career goes back a fair distance.  I can
easily remember days when "unsigned int" on a PC would _not_ have
provided the same type as "u32" -- not in Linux, but in other
environments.  In fact, this must still be true today in the embedded
world; plenty of 8-bit and 16-bit processors are still being sold.
Probably even more of them than 32-bit or 64-bit processors.

As far as I know, there is no guarantee anywhere in Linux that "u32"
will _always_ be a typedef for "unsigned int", even though it is now.

So you don't have to go that long back. Unless I'm mistaken ANSI C
defines unsigned integer to be in range from 0..65535 which makes it
16bit. It got extended by C90 or C99 which also introduced long long
(my memory may not be completely correct here).
If you take any piece of serious software and use on that compiler it
will blow up because most people assume an integer is 32bit and you end up with overflows.

So what should I learn from this Alan? If the variable I'm using should
hold values in the range 0..65535 I should use unsigned int. and if I
plan anything in the range 0..4294967295 I shall use u32?

Alan Stern

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux