In reviewing the basics, I've just learned that:

int var;

is equivilent (at least on my Windows box) to:

signed var; // meaning it defaults to signed.

and this made me explore what a char type might default to. However, as one
must cast a char variable to an int to output it as anything but a char, it
would seem that there is no meaning to this question.

Anyone know if char defaults to signed or unsigned? How can I see this?
(simple code).

Thanks, Patrick

Re: understand char type - warning: noob question :) by Igor

Igor
Thu Jun 08 19:53:40 CDT 2006

"Stick" <Stick@discussions.microsoft.com> wrote in message
news:C5EE65E8-9B1D-47A3-B06C-67E12F32A622@microsoft.com
> In reviewing the basics, I've just learned that:
>
> int var;
>
> is equivilent (at least on my Windows box) to:
>
> signed var; // meaning it defaults to signed.
>
> and this made me explore what a char type might default to. However,
> as one must cast a char variable to an int to output it as anything
> but a char, it would seem that there is no meaning to this question.

char, signed char and unsigned char are three distinct types. char must
have the same range of values as either signed char or unsigned char -
it is implementation-defined which one (and it's still a distinct type,
e.g. for the purposes of overload resolution).

On VC++, char defaults to being signed, but this can be changed with /J
compiler switch.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: understand char type - warning: noob question :) by John

John
Fri Jun 09 03:39:55 CDT 2006


"Stick" <Stick@discussions.microsoft.com> wrote in message
news:C5EE65E8-9B1D-47A3-B06C-67E12F32A622@microsoft.com...
> In reviewing the basics, I've just learned that:
>
> int var;
>
> is equivilent (at least on my Windows box) to:
>
> signed var; // meaning it defaults to signed.
>
> and this made me explore what a char type might default to. However, as
> one
> must cast a char variable to an int to output it as anything but a char,
> it
> would seem that there is no meaning to this question.

Not meaningless. If you assign it to an int, then you can get a negative or
a positive int.

int x;
unsigned char chu = -1;
x = chu;
cout << x << endl; // gives 255

signed char chs = -1;
x = chs;
cout << x << endl; // gives -1

> Anyone know if char defaults to signed or unsigned? How can I see this?
> (simple code).

char ch = -1;
x = ch;
cout << x << endl; // gives what?


--
John Carson