Is it possible to ensure the utilization of function-like macro version of putc
or getc
for example instead of the function versions?
For purposes of optimization and speed of run time execution.
You can test if the macros are defined with #ifdef getc
but if the macro is not defined, you cannot define it yourself. If the macros are defined, writing getc(f)
expands the macro.
Whether getc()
and putc()
are implemented as macros, inline functions or regular functions is not a guarantee of performance. Modern compilers may even inline the code at link time in static builds. Before you waste time on hand optimising this, use a benchmarking tool to determine where performance bottlenecks really hide.
If single byte I/O is a real concern, here are some hints to try and achieve better performance:
getc_unlocked()
and putc_unlocked()
and friends to bypass the stream locking mechanism.mmap
or an equivalent system dependent API.