Skip to content

Add printing to NULL in the Print class? #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
m-elias opened this issue Mar 1, 2023 · 3 comments
Closed

Add printing to NULL in the Print class? #525

m-elias opened this issue Mar 1, 2023 · 3 comments

Comments

@m-elias
Copy link

m-elias commented Mar 1, 2023

I'm working on a project where I tried Stream* stream = NULL when I didn't want output messages. While this compiled, my Teensy went into a boot loop. I've solved my issue by using overloaded functions with an if (stream != NULL) check but I wondered if adding NULL handling to the core Print class would be a interesting idea.

@facchinm
Copy link
Member

facchinm commented Mar 2, 2023

Hi @m-elias ,
the thing you are proposing is not very feasible at a platform level; however, adding a default NullStream object (that does nothing) is definitely a good idea.
The code would then need to be modified as
Stream* stream = &NullStream
and that instance would simply "do nothing"

@facchinm facchinm closed this as completed Mar 2, 2023
@m-elias
Copy link
Author

m-elias commented Mar 2, 2023

Is that something that needs to be added to the core or just to my individual sketch?

@matthijskooijman
Copy link
Collaborator

I think it is too specific for the core, better for a library.

In fact, it seems this library implements exactly that: https://github.com/RobTillaart/DEVNULL
Also, see https://github.com/bblanchon/ArduinoStreamUtils which has a bunch of stream utilities (but seems to lack a null stream, even though it would fit in nicely I think).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants