fork(1) download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. leftBitCount(-1);
  5. }
  6.  
  7. void leftBitCount(int x) {
  8. int b;
  9. int c;
  10. int s;
  11. int a = 0;
  12. a = ~x;
  13. a = a | (a >> 1);
  14. a = a | (a >> 2);
  15. a = a | (a >> 4);
  16. a = a | (a >> 8);
  17. a = a | (a >> 16);
  18. a = ~a;
  19. b = 0x11 | (0x11 << 8);
  20. c = b | (b << 16);
  21. s = a & c;
  22. showBits(b);
  23. showBits(c);
  24. showBits(s);
  25. }
  26.  
  27. void showBits(unsigned int w) {
  28. int arr[32];
  29. for (int i = 0; i < sizeof(w) * 8; i++) {
  30. if (w & 0x1) arr[i] = 1;
  31. else arr[i] = 0;
  32. w = w >> 1;
  33. }
  34.  
  35. for (int i = 31; i >= 0; i--) {
  36. if ((i+1) % 4 == 0) printf(" ");
  37. printf("%d", arr[i]);
  38. }
  39. printf("\n");
  40. }
  41.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function 'main':
prog.c:4:2: warning: implicit declaration of function 'leftBitCount' [-Wimplicit-function-declaration]
  leftBitCount(-1);
  ^
prog.c: At top level:
prog.c:7:6: warning: conflicting types for 'leftBitCount'
 void leftBitCount(int x) {
      ^
prog.c:4:2: note: previous implicit declaration of 'leftBitCount' was here
  leftBitCount(-1);
  ^
prog.c: In function 'leftBitCount':
prog.c:22:3: warning: implicit declaration of function 'showBits' [-Wimplicit-function-declaration]
   showBits(b);
   ^
prog.c: At top level:
prog.c:27:6: warning: conflicting types for 'showBits'
 void showBits(unsigned int w) {
      ^
prog.c:22:3: note: previous implicit declaration of 'showBits' was here
   showBits(b);
   ^
prog.c: In function 'showBits':
prog.c:29:4: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
    for (int i = 0; i < sizeof(w) * 8; i++) {
    ^
prog.c:29:4: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
prog.c:35:13: error: redefinition of 'i'
    for (int i = 31; i >= 0; i--) {
             ^
prog.c:29:13: note: previous definition of 'i' was here
    for (int i = 0; i < sizeof(w) * 8; i++) {
             ^
prog.c:35:4: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
    for (int i = 31; i >= 0; i--) {
    ^
prog.c: In function 'main':
prog.c:5:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
stdout
Standard output is empty