Try this C++ program with Borland bcc or GNU g++:
Code:
#include <iostream>
using namespace std;
int main()
{
bool x;
bool y;
x = false;
y = !x;
cout << "x = " << x << ", y = " << y << endl;
printf ("x = %08x, y = %08x\n\n", x, y);
y = ~x;
cout << "x = " << x << ", y = " << y << endl;
printf ("x = %08x, y = %08x\n", x, y);
return 0;
}
Then do the same thing in C, with <stdio.h> instead of <iostream>, int instead of bool for x and y (and without the cout <<, of course).
(Microsoft VC++ did give a warning with the C++ program about "unsafe use of type bool" with the ~ operator: not recommended, but gave the same result as the others.)
You really aren't supposed to use ~ with type bool, but sometimes programmers get away with things they aren't supposed to do --- often causing grief for themselves or others somewhere down the line.
Dave