Skip to content
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

PROGMEM methods for Print.cpp #1094

Closed
wants to merge 2 commits into from

Conversation

tius2000
Copy link
Contributor

@tius2000 tius2000 commented Apr 18, 2017

  • missing PROGMEM methods for class Print added
  • dynamic stack allocation for printf moved to new method vprintf

However, I have no idea how to fix the conflict with the new macro printf_P in FakePgmSpace.h :-(

(see #1067)

// (returns maxLen instead of required size)
while (1) {
char buffer[size + 1];
auto sz = m_vsnprintf(buffer, sizeof(buffer), fmt, va);
Copy link
Contributor

@ADiea ADiea Apr 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this PR should wait for #1077. Then you shuld have directly the correct size needed +1 ending char. So I would not use while(1) and wait for the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right @ADiea. I just added automatic PROGMEM support to #1077, so this PR might even no longer be needed.

{
va_list va;
va_start(va, fmt);
auto cnt = vprintf(fmt, va);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please only use auto when hiding an ugly/templetized type specifier. In this case it is size_t. IMHO it's faster to read and debug if you know the types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -26,12 +26,14 @@

#define INITIAL_PRINTF_BUFFSIZE 128

#undef printf_P
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should remove this here. If you do not want name collision you have 2 options: namespaces or explicit calling e.g. this.printf_P

Copy link
Contributor Author

@tius2000 tius2000 Apr 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, this is ugly and will cause problems. Therefore I would suggest the following procedure:

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I guess if printf / m_printf will be progmem safe, then no need for _P variant. For printf I do not care about speed so much, but sprintf I would keep it fast

@slaff slaff closed this Apr 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants