6 years, 8 months ago.

error: macro "putc" requires 2 arguments, but only 1 given

Hi all, I know, there are similar questions in the past but nobody answered. Compiling mbed using LpcXpresso or anyway using GCC/G++ compilers from ARM returns this error in RawSerial.cpp Serial.cpp, SerialBase.cpp and Stream.cpp on definition of metod int putc(int).

This error could happen only if putc is realized as a macro but it is realized in this way:

int _EXFUN(putc, (int, FILE *));

so _EXFUN expands as: int putc(int, FILE*)

Seems to me that putc is not a macro so the error message is quite strange. Any help would be appreciated. Thanks, Massimo

1 Answer

6 years, 5 months ago.

Hi,

I've had this problem as well when exporting programs for the KL25Z to CooCox. It comes about because the gcc-arm implementation of stdio.h defines getc() and putc() as macros, which conflicts with member functions of the same name in SerialBase etc.

For me, adding some brackets as follows works:

(pc.putc)(x);

As it forces the compiler to parse the (pc.putc) first, and doesn't apply the macro. Hopefully that works for you too :).

Russel