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

Fix pgm_read_ptr in AVR pgmspace.h#118

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

Merged
aentinger merged 1 commit intoarduino:masterfromtttapa:patch-1
Oct 7, 2020

Conversation

@tttapa
Copy link
Contributor

Originally,pgm_read_ptr used to cast its argument toconst void *, i.e. a pointer to read-only data.
This is incorrect, because the argument is a pointer to a pointer in "flash memory". You cannot cast it to
const void * and then dereference it, becausevoid is not an object type.
Also, the pointer itself is read-only, but the data could in theory be mutable.
The correct type should bevoid *const *, i.e. a pointer to a read-only pointer to any data.

bblanchon and CriptoCosmo reacted with thumbs up emoji
Originally, `pgm_read_ptr` used to cast its argument to `const void *`, i.e. a pointer to read-only data.  This is incorrect, because the argument is a pointer to a pointer in "flash memory". You cannot cast it to`const void *` and then dereference it, because `void` is not an object type.Also, the pointer itself is read-only, but the data could in theory be mutable.  The correct type should be `void *const *`, i.e. a pointer to a read-only pointer to any data.
@bblanchon
Copy link

I confirm that this change is necessary to fix the following error:

arduino/api/deprecated-avr-comp/avr/pgmspace.h:107:49: error: 'const void*' is not a pointer-to-object type #define pgm_read_ptr(addr) (*(const void *)(addr))                                                 ^

Please merge this pull request.

Copy link
Collaborator

@matthijskooijmanmatthijskooijman left a comment

Choose a reason for hiding this comment

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

Also looks good to me.

One nitpick: I would have a small preference to useconst void ** instead ofvoid *const *, which is a bit easier to read but AFAIU equivalent. This is also what is already used in practice in e.g. the SAMD core:https://github.com/adafruit/ArduinoCore-samd/blob/6a59e8347d01a9a7a51cd71f7981d154d851ba35/cores/arduino/avr/pgmspace.h#L106

@bblanchon
Copy link

@bblanchon
Copy link

@bblanchon
Copy link

@bblanchon
Copy link

@bblanchon
Copy link

As you see, there are many variants out there.
However, if we go back to theoriginal definition in avr-libc, we see that the macro casts the result tovoid*.
Therefore, to emulate the original macro, we should usevoid *const *, as@tttapa wrote.

@matthijskooijman
Copy link
Collaborator

But I'm saying that, AFAIU,const void** isexactly the same type asvoid *const *, it's just written in an IMHO more readable/common way. Or are you arguing that these types are different?

@bblanchon
Copy link

It's not a matter of taste; they are different types:

  • *(const void**) isconst void*
  • *(void *const *) isvoid*

@matthijskooijman
Copy link
Collaborator

Hm, seems I was wrong indeed, thanks for insisting.

So with that out of the way, the PR as it is now is indeed correct, so I'm for merging it.

Note that this also means that the SAMD and Arduino_STM32 versions are indeed also subtly broken (returningconst void* instead ofvoid*), though not as broken as the version in the ArduinoCore-API repo right now (which does not even dereference successfully).

bblanchon reacted with thumbs up emoji

@aentinger
Copy link
Contributor

Thank you to both@bblanchon and@matthijskooijman 🚀 I'll merge now.

@aentingeraentinger merged commit76e931e intoarduino:masterOct 7, 2020
@bblanchon
Copy link

Thanks !!!

aentinger reacted with thumbs up emoji

bblanchon added a commit to bblanchon/ClearCore-Arduino-wrapper that referenced this pull requestJul 14, 2023
Calling this macro causes the error "'const void*' is not a pointer-to-object type"Related toarduino/ArduinoCore-API#118Fixesbblanchon/ArduinoJson#1947
piernov added a commit to piernov/UCA_AIoT_Core that referenced this pull requestNov 18, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@matthijskooijmanmatthijskooijmanmatthijskooijman approved these changes

+1 more reviewer

@bblanchonbblanchonbblanchon approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@tttapa@bblanchon@matthijskooijman@aentinger

[8]ページ先頭

©2009-2025 Movatter.jp