473,324 Members | 2,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Does omitting the "signed" keyword change semantics?

What is the difference between char and signed char, short and unsigned
short, int and signed int, long and unsigned long?

Jul 23 '05 #1
4 1853
BigMan wrote:
What is the difference between char and signed char, short and unsigned
short, int and signed int, long and unsigned long?


Well, obviously, the range of values that they represent is different.
Signed types can represent negative numbers whereaas unsigned types use
the same bit patterns to represent large positive numbers.

But of course C and C++ don't have any run-time checks to stop you from
subtracting 1 from an unsigned 0. So it is tempting to think that the
types are not actually any different since in many common cases, e.g.
when you are doing addition and subtraction, the bit patterns will end
up the same whatever the types.

But there are plenty of places where it does matter. For example, when
you do formatted input/output, conversions (e.g. assign a shorter type
to a longer type - is it sign-extended?), comparisons (is 11111111
greater or less than 00000000?), and so on.

Using the correct types also helps the compiler to give you sensible
warnings.

--Phil.
Jul 23 '05 #2
Phil Endecott wrote:

But of course C and C++ don't have any run-time checks to stop you from
subtracting 1 from an unsigned 0.


Nor should they, since the result is well-defined.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 23 '05 #3
Sorry! What I meant was if there is a difference between char and
signed char, short and signed short, int and signed int, long and
signed long. I.e. does int (or char, short, long) means signed int (or
signed char, signed short, signed long respectively)?

Jul 23 '05 #4
On 12 Jun 2005 11:18:20 -0700, "BigMan" <Bi****@abv.bg> wrote:
What is the difference between char and signed char, short and unsigned
short, int and signed int, long and unsigned long?


char, signed char and unsigned char are special cases: they are three
separate types. Most compilers will have a compile parameter enabling
you to influence how plain char is treated -- either as signed or
unsigned. But plain char is a distinct type.

signed int and int, OTOH, are synonymous, as are signed long and long,
signed short and short, etc. IOW, integral types are signed unless you
write unsigned.

--
Bob Hairgrove
No**********@Home.com
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Sidney Cadot | last post by:
Hi all, Just browsing through my newly-acquired C99 spec, I was reading on the memcmp() function (7.21.4.1). It has a rather peculiar wording: int memcmp(const void *s1, const void *s2, size_t...
4
by: Ken Tough | last post by:
Seems like a simple thing to find out, but I'm struggling. I have googled, but everything I find is about implicit conversion, not explicit. Is this implementation-specific, or does ANSI/ISO...
81
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
86
by: Randy Yates | last post by:
In Harbison and Steele's text (fourth edition, p.111) it is stated, The C language does not specify the range of integers that the integral types will represent, except ot say that type int may...
35
by: Sunil | last post by:
Hi all, I am using gcc compiler in linux.I compiled a small program int main() { printf("char : %d\n",sizeof(char)); printf("unsigned char : ...
3
by: dhnriverside | last post by:
Hi guys I'm using Microsoft Word from asp.net, using VB Script CreateObject etc to load Word on the client. It keeps coming up with the "run active x control" dialog, saying that MSWord is...
134
by: jacob navia | last post by:
Hi Suppose you have somewhere #define BOOL int and somewhere else typedef BOOL int;
10
by: =?iso-8859-2?B?SmFuIFJpbmdvuQ==?= | last post by:
Hello everybody, this is my first post to a newsgroup at all. I would like to get some feedback on one proposal I am thinking about: --- begin of proposal --- Proposal to add...
26
by: John Harrison | last post by:
I have a problem. I want to compare an integral value, n, against three half open ranges as follows [-A, 0) // range 1 [0, B) // range 2 [B, C} // range 3 Each range corresponds to a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.