Some of the functions in stdio seem to have the stream as the last argument, for example:
char *fgets(char *restrict, int, FILE *restrict);
int fputs(const char *restrict, FILE *restrict);
size_t fread(void *restrict, size_t, size_t, FILE *restrict);
size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
while some have it as the first argument:
int fgetpos(FILE *restrict, fpos_t *restrict);
int fseek(FILE *, long, int);
Why is this inconsistency? Were these functions added at different time in the evolvement of the standard library? In that case which were first, and why was the convention changed?
I realize that it's more or less needed for fprintf
with friends to have the FILE*
first (or at least early) due to the ellipsis (and for fclose
and similar to have it first, and last).
A stream is a logical entity that represents a file or device, that can accept input or output. All input and output functions in standard C, operate on data streams. Streams can be divided into text, streams and binary streams.
The cstdio header file contains definitions for C++ for performing input and output. Include the standard header into a C++ program to effectively include the standard header <stdio. h> within the std namespace.
h: This header file contains mathematical functions. It contains functions such as sqrt, pow, exp, log, sin, etc.
I am convinced that a clear and evident answer will not be found to this question, although, this question is not opinion-based, as a clear answer exists somewhere, even though it is unreachable.
However, I recognize the frustration about the problem: one cannot easily work, if, besides learning the function names and what they depend on, memorizing the parameter order for each function individually. Instead, it would be nice to have a consistent parameter order.
To achieve that, one can implement a consistent stdio library, which would use consistent order for the parameters and would wrap each stdio function into such a function. Example:
int mystdio_fseek(long, int, FILE *);
This would return the result of
int fseek(FILE *, long, int);
So, the mystdio_
might be a prefix to make sure that names are almost similar, but different and the parameter order would be consistent. This way, one would need to remember only the function names, what each function depends on and there will be no longer need to memorize the parameter order for each function individually. One could use these methods whenever there will be no need for micro optimization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With