fork(1) download
  1. # include <stdio.h>
  2.  
  3. #define ISNEG(X) (!((X) > 0) && ((X) != 0))
  4.  
  5.  
  6. void
  7. display_result(int arg, int result)
  8. {
  9. printf("ISNEG(%d) is %stive\n", arg, (result ? "nega" : "posi"));
  10. }
  11.  
  12. void
  13. display_uresult(unsigned int arg, int result)
  14. {
  15. printf("ISNEG(%u) is %stive\n", arg, (result ? "nega" : "posi"));
  16. }
  17.  
  18. int main ()
  19. {
  20. short shrt = 5;
  21. short nshrt = -5;
  22. unsigned short ushrt = 5;
  23.  
  24. display_result(shrt, ISNEG(shrt));
  25. display_result(nshrt, ISNEG(nshrt));
  26. display_uresult(ushrt, ISNEG(ushrt));
  27.  
  28. int ni = -5;
  29. int i = 5;
  30. int zero = 0;
  31.  
  32. display_result(ni, ISNEG(ni));
  33. display_result(i, ISNEG(i));
  34. display_result(zero, ISNEG(zero));
  35. display_result(~zero, ISNEG(~zero)); // wrong
  36.  
  37. unsigned int uzero = 0;
  38. unsigned int ui = 5;
  39.  
  40. display_uresult(uzero, ISNEG(uzero));
  41. display_uresult(~uzero, ISNEG(~uzero));
  42. display_uresult(ui, ISNEG(ui));
  43.  
  44. long int li = -5;
  45. unsigned long int uli = 5;
  46.  
  47. display_result(li, ISNEG(li));
  48. display_uresult(uli, ISNEG(uli));
  49.  
  50. long long int lli = -5;
  51. unsigned long long int ulli = 5;
  52.  
  53. display_result(lli, ISNEG(lli));
  54. display_uresult(ulli, ISNEG(ulli));
  55.  
  56. return 0;
  57. }
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
ISNEG(5) is positive
ISNEG(-5) is negative
ISNEG(5) is positive
ISNEG(-5) is negative
ISNEG(5) is positive
ISNEG(0) is positive
ISNEG(-1) is negative
ISNEG(0) is positive
ISNEG(4294967295) is positive
ISNEG(5) is positive
ISNEG(-5) is negative
ISNEG(5) is positive
ISNEG(-5) is negative
ISNEG(5) is positive