info about

#1173370
For all integer types except char, 'signed' is implicit, so plain 'long'
is the same as 'signed long'.

char may be signed or unsigned - it is implementation dependent. Most
compilers allow you to specify whether it is signed or unsigned by
command line options, but it is better not to rely upon that, and use
the 'signed' or 'unsigned' keywords explicitly when it matters.

In other words, you don't really need to know because if it matters you
can always force it one way or another thus:

signed char x ;

or

unsigned char x ;


Clifford
#1173371
I think about many bugs may be occoured by defaults...
a simple case is when the compiler updated to newest version and the
compiler's manufacturer changed some default settins (for example,
signed to unsigned).

I always write the signed or unsigned and this much better human
readable (not need to figure out the compiler's defaults).

regards
#1173372
Toth Jozsef wrote:
> a simple case is when the compiler updated to newest version and the
> compiler's manufacturer changed some default settins (for example,
> signed to unsigned).

The ISO standard is clear; only the signedness of the plain char type is
implementation dependent, other types are unambiguous - so int and long
for example are always signed.

If using a char as a character (as intended), then it seldom matters
whether it is interpreted as signed or unsigned since you would not
expect to be doing arithmetic on it (at least not arithmentic for which
the signedness matters). If using char as a small integer on the other
hand, then it is always a good idea to be explicit.

Better yet, use of of the C99 size/sign specific types declared in
<stdint.h> such as uint8_t or int8_t.


Clifford

Reply

A question of your own? This thread is over 18 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.