Hello I request your help for the following:
I want to store constant data inside arrays for various purposes.
Sometimes this would be small strings, sometimes arrays with binary data.
I have tried around a lot using the C compiler for this purpose. All I was able to do so far is the following:
At first I define the data as a sequence of 8-bit pieces.
Then I create a const string containing this sequence.
Then I put numerous similar const strings into an array.
It compiles correctly, and I used it a few times.
I can obtain single array elements easily.
But, is it possible to make the definition more easy?
Is it possible for instance to put all the sequences directly in the const char * const array?
Creating numerous const strings works but maybe it can be avoided.
Another question I have if it is possible to build an array containing 5 bit elements (for instance), and only taking up 5 bits storage space?
I have shown an excerpt of a program that I am currently working on.
Previously, I only used textual strings, but now it is data pieces only requiring 5 bits.
I do know that PICs for instance on 16F baseline store constant string data using sequences of RETLW instructions, and then 8-bit values are returned.
If there is any easy advice, please do it.
But I can also continue to use it as explained above.
Edit: The reason why define is used to put together 8bit data is that normally I use this to support various languages. Some character sets are multiple byte, so I build them using cascading define sequences.
Edit: Actually currently I convert an assembler data table to C language. So the original data looks like this:
I want to store constant data inside arrays for various purposes.
Sometimes this would be small strings, sometimes arrays with binary data.
I have tried around a lot using the C compiler for this purpose. All I was able to do so far is the following:
Rich (BB code):
#define chr_a 0x04,0b11110,0b00101,0b00101,0b11110
#define chr_b 0x04,0b11111,0b10101,0b10101,0b01110
const char s_chr_a[]={chr_a};
const char s_chr_b[]={chr_b};
const char* const alpha_chr[]={s_chr_a,s_chr_b};
Then I create a const string containing this sequence.
Then I put numerous similar const strings into an array.
It compiles correctly, and I used it a few times.
I can obtain single array elements easily.
But, is it possible to make the definition more easy?
Is it possible for instance to put all the sequences directly in the const char * const array?
Creating numerous const strings works but maybe it can be avoided.
Another question I have if it is possible to build an array containing 5 bit elements (for instance), and only taking up 5 bits storage space?
I have shown an excerpt of a program that I am currently working on.
Previously, I only used textual strings, but now it is data pieces only requiring 5 bits.
I do know that PICs for instance on 16F baseline store constant string data using sequences of RETLW instructions, and then 8-bit values are returned.
If there is any easy advice, please do it.
But I can also continue to use it as explained above.
Edit: The reason why define is used to put together 8bit data is that normally I use this to support various languages. Some character sets are multiple byte, so I build them using cascading define sequences.
Edit: Actually currently I convert an assembler data table to C language. So the original data looks like this:
Rich (BB code):
/*
lc_d:
dw 4
dw b'11111'
dw b'10001'
dw b'10001'
dw b'01110'
lc_e:
dw 4
dw b'11111'
dw b'10101'
dw b'10101'
dw b'10001'
lc_f:
dw 4
dw b'11111'
dw b'00101'
dw b'00101'
dw b'00001'
Last edited: