blogstrapping

More About Debian Clang Stupidity

I wrote a toy program in C that looked like this:

#include <stdio.h>

int a, b;

int main() {
  a = 3;
  b = 5;

  printf("a = %d\n", a);
  printf("b = %d\n", b);

  a = a + b;
  b = a - b;
  a = a - b;

  printf("a = %d\n", a);
  printf("b = %d\n", b);

  return (0);
}

I tried compiling it:

$ clang varswap.c -o varswap
In file included from varswap.c:1:
In file included from /usr/include/stdio.h:28:
/usr/include/features.h:323:10: fatal error: 'bits/predefs.h' file not found
#include <bits/predefs.h>
         ^
1 diagnostic generated.

So . . . no compiled program resulted. Here's the same program again, with a critical line removed:

int a, b;

int main() {
  a = 3;
  b = 5;

  printf("a = %d\n", a);
  printf("b = %d\n", b);

  a = a + b;
  b = a - b;
  a = a - b;

  printf("a = %d\n", a);
  printf("b = %d\n", b);

  return (0);
}

I tried compiling that:

$ clang varswap.c -o varswap
varswap.c:7:3: warning: implicitly declaring C library function 'printf' with type 'int (char const *, ...)' [-pedantic]
  printf("a = %d\n", a);
  ^
varswap.c:7:3: note: please include the header <stdio.h> or explicitly provide a declaration for 'printf'
2 diagnostics generated.

Hmm. Different error message. The really interesting part, though, is that I then had a varswap file:

$ ./varswap
a = 3
b = 5
a = 5
b = 3

As mentioned in Reminding Myself How To Write Simple C, I do not have these problems on a FreeBSD laptop. It compiles with the #include <stdio.h> line without complaints, and gives me a program that Just Works.