Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support printing constant strings containing nulls#5747

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
eric-wieser wants to merge2 commits intoarduino:masterfromeric-wieser:patch-3

Conversation

@eric-wieser
Copy link
Contributor

@eric-wiesereric-wieser commentedDec 22, 2016
edited
Loading

What's changed

  1. Serial.print("Hello""\0""World")
    • Before: printsHello
    • After: printsHello\0World
  2. Serial.print("Hello")
    • Before: invokesstrlen
    • After: does not, is faster. Code size should be unchanged
  3. Serial.println("Hello")
    • Before: invokesstrlen
    • After: does not, is faster. Slightly increased code size, due to inlining

Thoughts?

This only changes the behaviour of code like `Serial.print("Hello""\0""World")`, where writing the null byte is clearly intended.This also gives a speed boost for all calls with constant strings
@matthijskooijman
Copy link
Collaborator

I'm not so sure if this is really a good idea, since now:

write("foo\0bar");

and

char *ptr = "foo\0bar";write(ptr);

Will have different results and I'm not sure that's really a good idea.

Also, Ithink that:

char buf[10];buf[0] = 'X';buf[1] = '\0';write(buf);

will now print 10 bytes, even though only 2 is intended. Since this sort of thing is likely to occur in sketches, this breaks compatibility.

Regarding handling of strings with embedded zeroes, you might be interested in#1936 which improves the String class to better handle them.

@PaulStoffregen
Copy link
Contributor

Thoughts?

Isn't this what write(buf, length) is supposed to do?

Ideally, both write() functions ought to take (const void *) type, but whether even that can be considered changeable at this late stage in Arduino's development is a good question?

@eric-wieser
Copy link
ContributorAuthor

I think that [...] will now print 10 bytes, even though only 2 is intended. Since this sort of thing is likely to occur in sketches, this breaks compatibility.

Yep, you're right - this is not an acceptable change

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@eric-wieser@matthijskooijman@PaulStoffregen

[8]ページ先頭

©2009-2025 Movatter.jp