Ben Pfaff said:
Thad Smith said:
Richard said:
Most good programmers don't #include C source because in almost all
circumstances it's a bad idea.
I agree. [...]
Not much of an answer, though. "I don't do <foo> because in
almost all circumstances it's a bad idea."
That's why I went on to say:
"Mostly, you're very likely to be heading for trouble the moment you try to
#include that C source in two separate parts of your program. Also, of
course, it does mean that you have to compile everything all the time,
instead of just compiling the bits that have changed - which is a complete
waste of time."
It is true that some good programmers do #include C source on vanishingly
rare occasions, but it was my considered opinion that the chances are very
slim indeed of an explanation of that fact being useful to someone who (at
a guess) is at a comparatively early stage in his or her C education.
About a decade ago, I wrote something similar to Thad's hack, and it was
(rightly, IMHO) rejected at code review. The sigh was along the lines of
"yes, all right, Richard, very good - now go write something we can read".
About five years ago, I saw something of the kind in the graphics rendering
code for a browser, with perhaps slightly more justification - it was
clear to me that the programmer /wanted/ to write an inline function, but
the code had to work on so many different platforms that using the
"inline" keyword was simply not an option. Evidently, he considered the
performance benefits to outweigh the maintenance cost, and he may well
have been right. I suspect he was, actually, but it wasn't my job to
establish this either way, so I didn't.