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

[Due] pgm_read_ptr causes error #5698

Closed
bobc opened this issue Dec 10, 2016 · 1 comment
Closed

[Due] pgm_read_ptr causes error #5698

bobc opened this issue Dec 10, 2016 · 1 comment
Labels
Board: Arduino Due Applies only to the Due Type: Bug

Comments

@bobc
Copy link
Contributor

bobc commented Dec 10, 2016

Arduino IDE 1.6.8
Arduino AVR Boards 1.6.10
Arduino SAM Boards 1.6.9

On Mega2560, the following sketch compiles OK:

void setup() {
  // put your setup code here, to run once:
  char str_debug_1[] PROGMEM = "ECHO";
  Serial.print((char*)pgm_read_ptr(&str_debug_1));
}

void loop() {
  // put your main code here, to run repeatedly:
}

On Due, the same sketch has a compile error :

In file included from C:\Users\bob\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.9\cores\arduino/Arduino.h:31:0,

                 from C:\Users\bob\AppData\Local\Temp\build3a01f77cc023d803352a39f55ca441db.tmp\sketch\sketch_pgm_read_test.ino.cpp:1:

C:\Users\bob\Documents\Arduino\sketch_pgm_read_test\sketch_pgm_read_test.ino: In function 'void setup()':

C:\Users\bob\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.9\cores\arduino/avr/pgmspace.h:106:49: error: 'const void*' is not a pointer-to-object type

 #define pgm_read_ptr(addr) (*(const void *)(addr))

                                                 ^

C:\Users\bob\Documents\Arduino\sketch_pgm_read_test\sketch_pgm_read_test.ino:6:23: note: in expansion of macro 'pgm_read_ptr'

   Serial.print((char*)pgm_read_ptr(&str_debug_1));

                       ^

exit status 1
Error compiling for board Arduino Due (Programming Port).

Inspection of pgm_read_ptr (in avr/pgmspace.h) for Due shows : -
#define pgm_read_ptr(addr) (*(const void *)(addr))

This macro casts the argument void *, then tries to dereference a void *, which is guaranteed to never work.

Probably, the cast to (void *) is not needed.

@facchinm facchinm added Board: Arduino Due Applies only to the Due Type: Bug labels Dec 12, 2016
@agdl
Copy link
Member

agdl commented Feb 8, 2017

This issue was moved to arduino/ArduinoCore-sam#21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Board: Arduino Due Applies only to the Due Type: Bug
Projects
None yet
Development

No branches or pull requests

3 participants