Do you know why the code below fails to compile?
#include <iostream>
namespace C {
extern "C" {
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> // open()
#include <unistd.h> // read()
}
}
int main(int argc, char** argv) {
int fd = C::open("./main.cpp", O_RDONLY);
C::read(fd, 0, 0);
return 0;
}
The error from the GCC 4.4 compiler is:
error: ‘read’ is not a member of ‘C’
You can not inject everything into a namespace under a header. In this case,
readis a macro and it is evaluated to something else before namespace resolution rules take effect.