0

I am doing a project that uses a library with source code I want to leave unaltered. Inside one of the library's source code files is a global const c-style string array that I want to alter externally from another file in the project:

const u8 STRING_PRODUCT[] PROGMEM = USB_PRODUCT;

By default global constants have internal linkage. Is there anyway to possible change this array without touching the code in this file? Or can I at least somehow get the memory address of this array and then use a pointer to alter it? Thank you!

  • 1
    No, that's not possible. – πάντα ῥεῖ Oct 05 '20 at 05:15
  • 1
    What is the *actual* and underlying problem you need to solve? Why do you think that problem could be solved by modifying constant data? – Some programmer dude Oct 05 '20 at 05:22
  • 1
    Also, the the `PROGMEM` usage indicates an embedded system, where the data could be placed in read-only memory. Which means that even using trickery won't work in that case. – Some programmer dude Oct 05 '20 at 05:23
  • Okay, so the library I'm referring to here is the Arduino core library, specifically the USB source code. If you make a USB arduino game controller, keyboard or midi controller the name of whatever board you are using is what becomes the name on your computer's USB device list when you plug it in. The *only* way to modify the name is by actually modifying the source code files, but this means that anyone who uses my project also has to modifying their own Arduino core libraries, which will be difficult for less technical people. – Dylan Morrison Oct 05 '20 at 05:58
  • How is USB_PRODUCT defined? – Surt Oct 05 '20 at 09:44

1 Answers1

0

No need to modify the source code. USB_PRODUCT is defined in USBCore.cpp only if it's not already defined, so just define it as whatever you want when compiling the library. (Reference)

Nick Matteo
  • 4,453
  • 1
  • 24
  • 35