10 years, 1 month ago.

printf : Non-POD class type passed through ellipsis

This code returns 2 warnings when compiled:

#include "mbed.h"

AnalogIn   left(PTC2);

int main() {
        float dummy;
        dummy = left;
        printf("%f\r\n",dummy);
        printf("%f\r\n",left);
        printf("%f\r\n", left.read());
        printf("%X\r\n", left.read_u16());
}

Warning: Non-POD class type passed through ellipsis in "main.cpp", Line: 9, Col: 25
Warning: Argument is incompatible with corresponding format string conversion in "main.cpp", Line: 9, Col: 25

I understand why this happens and how to use an easy workaround (code in lines 7 & 8 - extra variable needed).
Will the shorthand read (line 9) lead to unpredictable results or memory leaks?
If using an intermediate variable is the only solution, perhaps we need to add a warning to the API documentation.
Or do we need to classify this under 'common knowledge'.

Note : This also applies to the shorthand read used in DigitalIn.

Glad I found this - it helped me. Clearly the "common" in "common knowledge" is relative. ;-)

posted by Mike G 20 Apr 2016
Be the first to answer this question.