Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Unsinged types

Reply
Thread Tools

Unsinged types

 
 
Jase Schick
Guest
Posts: n/a
 
      07-19-2012
Hi Does C still need unsigned types? My preferred language Java manages
perfectly well without them. Do many people ever use unsigned types
nowadays and if so why? In a 64-bit world, the extra range is rarely
worth the hastle it seems to me.

Jase
 
Reply With Quote
 
 
 
 
Ben Bacarisse
Guest
Posts: n/a
 
      07-19-2012
Jase Schick <> writes:

> Hi Does C still need unsigned types?


Yes. C needs them because of how it defines signed integer types.
Signed integer values can be represented in one of three ways, and the
language allows signed integer arithmetic to overflow in an undefined
way. Also, some operations on signed types are undefined (some shifts
for example). All this is to permit the very widest possible range of
implementations without the need to simulate an arithmetic type that the
hardware does not have.

There is a language not entirely unlike C which would no longer need
them, but it would have more constrained signed integer types.

> My preferred language Java manages
> perfectly well without them. Do many people ever use unsigned types
> nowadays and if so why? In a 64-bit world, the extra range is rarely
> worth the hastle it seems to me.


It's very hard to avoid using them! malloc's argument is an unsigned
integer, the result of sizeof and strlen are unsigned values, etc.

Your argument about the 64-bit world will ring hollow to people using C
in the 16- and 32-bit words! Whilst C99 requires a 64-bit type, there
are many environments without a C99 compiler, and probably some where
64-bit arithmetic needs to be implemented in software.

--
Ben.
 
Reply With Quote
 
 
 
 
jacob navia
Guest
Posts: n/a
 
      07-19-2012
Le 19/07/12 22:29, Ben Bacarisse a écrit :
>
> Your argument about the 64-bit world will ring hollow to people using C
> in the 16- and 32-bit words! Whilst C99 requires a 64-bit type, there
> are many environments without a C99 compiler, and probably some where
> 64-bit arithmetic needs to be implemented in software.
>


Those are just efficiency details unworthy of the attention of a Java
programmer that will always use the biggest types combined with the
slowest possible programming. Java leads to that kind of mindset.

Java is another world.
 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      07-19-2012
Jase Schick <> writes:

> Hi Does C still need unsigned types? My preferred language Java manages
> perfectly well without them. Do many people ever use unsigned types
> nowadays and if so why? In a 64-bit world, the extra range is rarely
> worth the hastle it seems to me.


Many quantities are naturally unsigned; for example, counts and
sizes. These quantities are most naturally modeled with unsigned
types.
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      07-20-2012
On 7/19/2012 6:47 PM, Ben Pfaff wrote:
> Jase Schick <> writes:
>
>> Hi Does C still need unsigned types? My preferred language Java manages
>> perfectly well without them. Do many people ever use unsigned types
>> nowadays and if so why? In a 64-bit world, the extra range is rarely
>> worth the hastle it seems to me.

>
> Many quantities are naturally unsigned; for example, counts and
> sizes. These quantities are most naturally modeled with unsigned
> types.


Indeed. If you use a singed type to hold an inherently
unsinged value, you're playing with fire.

--
Eric Sosman
d
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      07-20-2012
Eric Sosman <> writes:

> On 7/19/2012 6:47 PM, Ben Pfaff wrote:
>> Jase Schick <> writes:
>>
>>> Hi Does C still need unsigned types? My preferred language Java manages
>>> perfectly well without them. Do many people ever use unsigned types
>>> nowadays and if so why? In a 64-bit world, the extra range is rarely
>>> worth the hastle it seems to me.

>>
>> Many quantities are naturally unsigned; for example, counts and
>> sizes. These quantities are most naturally modeled with unsigned
>> types.

>
> Indeed. If you use a singed type to hold an inherently
> unsinged value, you're playing with fire.


I agree with the "indeed", but I am not sure I see why you added that
one would be "playing with fire". Can you say a bit more about that?

--
Ben.
 
Reply With Quote
 
Stephen Sprunk
Guest
Posts: n/a
 
      07-20-2012
On 19-Jul-12 20:32, Ben Bacarisse wrote:
> Eric Sosman <> writes:
>> On 7/19/2012 6:47 PM, Ben Pfaff wrote:
>>> Many quantities are naturally unsigned; for example, counts and
>>> sizes. These quantities are most naturally modeled with unsigned
>>> types.

>>
>> Indeed. If you use a singed type to hold an inherently unsinged
>> value, you're playing with fire.

>
> I agree with the "indeed", but I am not sure I see why you added that
> one would be "playing with fire". Can you say a bit more about that?


It's a clever reference to "singed" types. Note the spelling.

I was trying to work up something similar, but he beat me to it.

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      07-20-2012
On 7/19/2012 9:32 PM, Ben Bacarisse wrote:
> Eric Sosman <> writes:
>
>> On 7/19/2012 6:47 PM, Ben Pfaff wrote:
>>> Jase Schick <> writes:
>>>
>>>> Hi Does C still need unsigned types? My preferred language Java manages
>>>> perfectly well without them. Do many people ever use unsigned types
>>>> nowadays and if so why? In a 64-bit world, the extra range is rarely
>>>> worth the hastle it seems to me.
>>>
>>> Many quantities are naturally unsigned; for example, counts and
>>> sizes. These quantities are most naturally modeled with unsigned
>>> types.

>>
>> Indeed. If you use a singed type to hold an inherently
>> unsinged value, you're playing with fire.

>
> I agree with the "indeed", but I am not sure I see why you added that
> one would be "playing with fire". Can you say a bit more about that?


It's a pnu.

--
Eric Sosman
d
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      07-20-2012
Stephen Sprunk <> writes:

> On 19-Jul-12 20:32, Ben Bacarisse wrote:
>> Eric Sosman <> writes:
>>> On 7/19/2012 6:47 PM, Ben Pfaff wrote:
>>>> Many quantities are naturally unsigned; for example, counts and
>>>> sizes. These quantities are most naturally modeled with unsigned
>>>> types.
>>>
>>> Indeed. If you use a singed type to hold an inherently unsinged
>>> value, you're playing with fire.

>>
>> I agree with the "indeed", but I am not sure I see why you added that
>> one would be "playing with fire". Can you say a bit more about that?

>
> It's a clever reference to "singed" types. Note the spelling.
>
> I was trying to work up something similar, but he beat me to it.


Well, I'm dyslexic so that's just made my day!

--
Ben.
 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      07-20-2012
On Jul 19, 9:03*pm, Jase Schick <nos...@nospam.com> wrote:

> Hi Does C still need unsigned types? My preferred language Java manages
> perfectly well without them. Do many people ever use unsigned types
> nowadays and if so why? In a 64-bit world, the extra range is rarely
> worth the hastle it seems to me.


raw bytes (or octets) are often emulated with "unsigned char" (I know,
a char doesn't have to be 8 bits but I've never actually used a
system
where it wasn't (I understand some DSPs do this)). And raw bytes are
usefukl for comms stuff, encryption, compression, signal processing
etc. etc.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unsinged types Jase Schick C Programming 11 07-23-2012 10:12 PM
Comparing singed to unsinged warning Nevil Lesdog C Programming 7 08-24-2007 01:45 AM
writing binary data whose size exceeds unsinged it mohammad.nabil.h@gmail.com C Programming 14 01-28-2006 12:18 PM
warning - comparing a signed value to an unsinged value Kevin Goodsell C Programming 30 10-22-2003 12:12 PM
Unsinged char to int Joseph Suprenant C Programming 2 08-18-2003 04:09 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57