arduino / arduino/ArduinoCore-sam

[Due] pgm_read_ptr causes error

Open
#21 3 comments 0 reactions 0 assignees View on GitHub
Board: Arduino Due Type: Bug
Dominant language
HTML
Stars
91
Forks
112
PR merge metrics
No merged PRs in 30d

Description

_From @bobc on December 10, 2016 12:31_

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.

_Copied from original issue: arduino/Arduino#5698_

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with avr/pgmspace.h, especially the pgm_read_ptr definition shown in the issue, and reproduce the supplied sketch on an Arduino Due. Done means the sketch compiles on the Due without regressing the reported Mega2560 behavior; no separate test file is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.