Question: d=1,-d==?
Let's see what the answer will look like:
-----------------------------
What is the output of the following code?
int main () {
Char dt = ' \1 ';
Long TDT;
TDT =-dt;
printf ("%ld\n", TDT);
}
My first reaction was that this output should be "-1". I think you think so, too. But what if the output is on a 64-bit system? I hope it is also "-1". Let's see if this is the case.
Let's test it.
#xlc-q64 a.c-qlanglvl=extended
#./a.out
4294967295
!! The output here is "4294967295" instead of "1".
Don't worry, it's possible we missed something.
Before answering the previous question, let's look at the following code snippet:
"Char dt = ' \1 ';" -dt; "
For this code snippet, can we confirm that the DT variable is signed or unsigned? C
Let's look at what the C language standard says:
The implementation shall define char to have the same range, representation, and behavior as either signed char or Unsigne D Char.
This means that the standard does not require symbols for char type variables. We're looking at the XL compiler's documentation Http://publib.boulder.ibm.com/infocenter/comphelp/v111v131/topic/com.ibm.xlc111.aix.doc/language _ Ref/ch.html
Inside said:
By default, char behaves like a unsigned char. To change this default, can use The-qchars option or the #pragma chars directive. See-qchars for more information.
It appears that in the XL compiler, char defaults to unsigned. We can use-qchars to change this default behavior. Let's test this out:
#xlc-q64 a.c-qlanglvl=extended-qchar=signed
#./a.out
-1
That's great. We seem to have understood.