4 ms·
An alternative to the ritual include foo.h as the first line of foo.c strategy is to compile each header individually, `clang -x c -Wall foo.h -c -o /dev/null`
by JonChesterfield 3y ago
An alternative to the ritual include foo.h as the first line of foo.c strategy is to compile each header individually, `clang -x c -Wall foo.h -c -o /dev/null` or similar. That catches roughly the same developer intent.
Similar to the cross compiled / native distinction, it's probably a good idea to put platform specific things behind an interface up front. Link time is a good point to swap out win32 for linux or similar and implementing the second target is much easier if you drew the line up front. The platform layer might also be one worth writing a mock for as part of testing.
- o11c 3y agoThe problem with `-x c foo.h` is that `#pragma once` isn't legal in the top-level source file. There might be other problems too. Using manual header guards is a bug-prone waste. Nobody has ever demonstrated me a case where `#pragma once` fails to work with compilers from the last decade or two.
- JonChesterfield 3y agoI've heard that `#pragma once` fails to work in the top-level source file, such as when compiling a header using -xc to see whether it is independently well formed...