Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[General] Getting a constant ragged array entirely in flash memory from standard C99

Status
Not open for further replies.

miniwinwm

Newbie level 3
Joined
Feb 18, 2018
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
21
If I have a ragged array of strings, defined like this...

Code:
static const char * const labels[] = {"Elk", "Horse", "Hog"};

with GCC the strings go into flash memory but the array of char pointers goes into RAM. I know I can force both parts into flash by creating a section in the linker script and referring to it in the source code before the array definition, but this then means that my code is compiler specific and also depends on an outside file as well (the linker script). Is anyone aware of any trick using only standard C99 that will get all parts into flash memory so that it compiles and does what I want with both GCC and other different compilers?
 

May be good to try specify pointers location directly?
Code:
static const char value1[] = "Elk";
static const char value2[] = "Horse";
static const char value3[] = "Hog";

static const char * const labels[] = {value1, value2, value3};
 

May be good to try specify pointers location directly?
Code:
static const char value1[] = "Elk";
static const char value2[] = "Horse";
static const char value3[] = "Hog";

static const char * const labels[] = {value1, value2, value3};

Thank you for the suggestion. I will try that on a variety of compilers and see what they do and report back.
 

Another option:
Code:
static const char * const labels[] = {(const char *)"Elk", (const char *)"Horse", (const char *)"Hog"};
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top