cmacros

Is it possible to use the function-like macro version of a function instead of the function versions of the C standard library?


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.


Solution

  • 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: