-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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/F: section type conflict with __c #3351
Comments
OK, it obviously had nothing to do with being is a class (and so being in a seperate file). You just cannot use const uint32_t INTERVAL = 5000;
const char* testString PROGMEM = "Testing 1 ";
// Print a string from Program Memory directly to save RAM
void printProgStr (HardwareSerial* serial, const char* str)
{
char c;
if (!str)
return;
while ((c = pgm_read_byte(str++)))
serial->print(c);
}
void setup() {
Serial.begin(115200);
}
void loop() {
static uint32_t previousMillis = 0;
if ((millis() - previousMillis) > INTERVAL) {
previousMillis = millis();
printProgStr(&Serial, testString);
Serial.println(F("Testing_F"));
}
} |
Please see #3369 for a possible solution. |
@bertmelis did you test the solution found in #3369? |
Or I just don't understand the solution, or it doesn't solve my "error". I'm trying to put debug messages in PROGMEM using an array of char pointers, as in Nick Gammon's blogpost. These debug messages are used in a class-library, for now without any namespace defined. I had all the declarations and initialisations in a header file. |
While the declaration can be, the initializations can't be in the header; as mentioned in #3369. |
But then also: I've got a class method with But I'll ask it in another way: are there any thoughts on improving the issue? Or shall I live with it? (in case of the latter, I'll modify my code to deal with it and close the issue) |
You can move the actual string into a const variable that is declared in the header, leaving the Serial.println in place. This is really what you would want anyhow. Currently, anything in a F("") will be a duplicated string, even if the text is the same. For any work other than simple examples and sketches, you really want a separate .h/.cpp that contain all your strings. |
Closing due to user error. |
I haven't got enough understanding of the inner working to assert if this is a coding error, or a bug, but I've got the following:
sketch:
TestClass.h:
TestClass.cpp:
Compiling results in an error:
TestClass.cpp:3: error: TestClass::_testString causes a section type conflict with __c
Removing the
F
macro solved the error as does removing thePROGMEM
modifier. However, I'd like to use both. eg: list of error messages and printing small debug messages, both from progmem.The text was updated successfully, but these errors were encountered: