Why is get_console in mbed_retarget.cpp static (ie: "private")

I’m writing a Stream writer for the ArduinoJSON library and I want to dump the JSON packet to the stdout console. Later on, I plan to retarget the console to SWO as I need the debug UART for other purposes.

I was thinking to just call the get_console function in mbed_retarget.cpp but it is declared static and therefore inaccessible in other source files (similar to a private member of a class).

I’m wondering if there’s any real design decision behind this? I am not aware of another way to get the default stdio FileHandle instance without reimplementing get_console verbatim (ie: checking for overrides on the application and target level first).

This is fine if you only plan on using C-style function calls, but I want to use the STDIO FileHandle as a C++ object.

Hello George,

I don’t have an answer to your question, but I think you can get the default stdio FileHandle for the console without reimplementing the get_console by passing the STDOUT_FILENO file descriptor to the mbed_file_handle function:

FileHandle *defaultStdioFileHandle = mbed_file_handle(STDOUT_FILENO);  // for CONSOLE
1 Like

Nice, exactly what I was looking for!