K
Keith Thompson
<snip>
*Please* don't snip attribution lines (lines of the form
discussion easier to follow, and giving proper credit is just polite.
[...]
How about Fputs then?
If you must do it, I suppose Fputs is a decent name. Some very old
linkers don't necessarily distinguish between upper and lower case for
external names, but I don't *think* that's likely to be a problem in
practice.
But I'm hesitant to offer too much advice on what to call these
things, since I think they're a bad idea in the first place. The
rules really aren't all that complex. You'll likely spend less time
learning them than you'd spend implementing your aliases -- and as a
result, you'll be better able to read other people's code (because
others aren't going to use your aliases), and other people will be
better able to read your code.
Normally I wouldn't put a comment - I think having int as the default
return type really helps streamline code. The comment was because
several people from this group recently expressed to me a strong
preference for main returning int not void, so I wanted to emphasize
that I'm now following their advice.
Bravo. But the point is that you only followed *part* of their
advice. Leaving out the word "int" is allowed (in C90, but not in
C99), but you gain nothing by doing so. Leaving out the word "void"
is also allowed, but again, you gain nothing by doing so. Change it
from "main()" to "int main(void)", and get into the habit of writing
it that way. Trust me on this; you'll be happier in the long run.
My stdio.h implements std(in|out|err) as macros, so I thought it best
to be on the safe side and typecast. (In fact there's a funny comment
about that in stdio.h:
/* C89/C99 say they're macros. Make them happy. */
)
Yes, the standard requires stdin, stdout, and stderr to be macros. It
also requires those macros to expand to expressions of type FILE*.
There is no realistic chance that an implementation will get this
wrong. If one did, it's not likely that casting ("typecast" isn't a
word unless you're talking about actors) will do any good.
[...]
Hmmm, does it really seem like such an outlandish thing? After all if
another programmer does read my code he'll have easy access to any
macro definitions, so that shouldn't cause too much difficulty.
Yes, it really does seem like such an outlandish thing. How is
someone reading your code going to know where your macro definitions
are? Presumably they'd be in some header you've written, but where is
it? Did you put it in the same directory as the source file that uses
it, or is it in a separate "include" directory, or is it off somewhere
else altogether?
And if I have to track down your macro definition to figure out what
Fputs(foo, bar) means, that tells me that it really means
fputs(bar, foo) -- but I *still* have to know that fputs() expects a
char* followed by a FILE*.
I can certainly understand the temptation to try to turn C into
something just a little bit better. The original Bourne shell under
Unix was originally written using a set of macros that made the
source look Pascalish:
#define BEGIN {
#define END }
#define IF if (
#define THEN )
#define ELSE } else {
The result was nearly illegible both to C programmers and to Pascal
programmers.
I like some languages better than others, but I generally try to
accept each language on its own terms.
In the 8th of Henry Spencer's "The Ten Commandments for C
Programmers", he wrote that "thy creativity is better used in solving
problems than in creating beautiful new impediments to understanding".