[Dev-C++] using iso646 (words for symbol of bit operations)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Carlos d. M. <cg...@wo...> - 2002-08-08 18:40:26
|
I saw a contest I thought iteresting to do, I wrote this:
This compiles:
#include <stdiostream.h>
#include <stdlib.h>
#include <math.h>
#include <iso646.h>
short int compare(const long int, const long int);
int main()
{
long int a = 45, b = 54, x = 3, y=3, m=56, n=32;
int res;
printf("%ld-%ld= %hd\n%ld-%ld=%hd\n%ld-%ld=%hd", a, b, compare(a,b), x,
y, compare(x,y), m, n, compare(m,n));
system("PAUSE");
return 0;
}
short int compare(const long int first, const long int second){
long int res1, res2 = 2, res3, unsi;
short int result = 0;
res1 = second - first;
res1 >>= 30;
unsi = res1 ^ res2;
res3 = second - first - 1;
res3 >>= 30;
res3 ^= res2;
unsi &= res3;
result = 2 - unsi;
return result;
}
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
This don't (variables of the function are considered not declared from
line 25):
#include <stdiostream.h>
#include <stdlib.h>
#include <math.h>
#include <iso646.h>
short int compare(const long int, const long int);
int main()
{
long int a = 45, b = 54, x = 3, y=3, m=56, n=32;
int res;
printf("%ld-%ld= %hd\n%ld-%ld=%hd\n%ld-%ld=%hd", a, b, compare(a,b), x,
y, compare(x,y), m, n, compare(m,n));
system("PAUSE");
return 0;
}
short int compare(const long int first, const long int second){
long int res1, res2 = 2, res3, unsi;
short int result = 0;
res1 = second - first;
res1 >>= 30;
unsi = res1 xor res2; <-- line 25 not declared
res3 = second - first - 1;
res3 >>= 30;
res3 xor_eq res2;
unsi and_eq res3;
result = 2 - unsi;
return result;
}
Yes, I know there is people who do not like systempause.
|