|
|
View previous topic :: View next topic |
Author |
Message |
Flavio58
Joined: 08 Sep 2003 Posts: 21
|
Pointer in struct ..... |
Posted: Tue Jun 24, 2003 8:35 am |
|
|
I tried to use some pointers into a structure but the compiler show me an error ...
My struct si :
struct errorMessage {
char *language1;
char *language2;
} errs[] = {
{ "msg1", "msg2" },
{ "msg3", "msg4" }};
Why this construct is not correct ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515518 |
|
|
Sherpa Doug Guest
|
Re: Pointer in struct ..... |
Posted: Tue Jun 24, 2003 9:02 am |
|
|
:=I tried to use some pointers into a structure but the compiler show me an error ...
:=
:=My struct si :
:=
:=struct errorMessage {
:= char *language1;
:= char *language2;
:=} errs[] = {
:= { "msg1", "msg2" },
:= { "msg3", "msg4" }};
:=
:=Why this construct is not correct ?
It looks like you are trying to use a pointer into ROM. This is forbidden by the Harvard architecture of the PIC processors, not just by the compiler. Some compilers have work-arounds but they are all convoluted and painful.
Look in the CCS manual under "Common Questions and Answers" at "How can a constant data table be placed in ROM? on page 189 of my manual.
Also search for "pointer to ROM" on this BBS.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515526 |
|
|
R.J.Hamlett Guest
|
Re: Pointer in struct ..... |
Posted: Tue Jun 24, 2003 9:09 am |
|
|
:=I tried to use some pointers into a structure but the compiler show me an error ...
:=
:=My struct si :
:=
:=struct errorMessage {
:= char *language1;
:= char *language2;
:=} errs[] = {
:= { "msg1", "msg2" },
:= { "msg3", "msg4" }};
:=
:=Why this construct is not correct ?
Because you cannot have pointers to constant strings. This is a well documented 'lack' in the CCS C, caused by the way they handle the processors architecture (remember the RAM, and ROM, are addressed seperately).
As written, the "MSGx" declarations, are automatically constants, and then the compiler can't deal with these for pointers.
You can have the pointers fine, but only by initialising the arrays 'after the event', and using RAM to store the strings.
You can also 'kludge' it, by using something like:
const char message[] = "msg1\0msg2\0msg3\0msg4"
#define MSGADD1 0
#define MSGADD2 5
#define MSGADD3 15
#define MSGADD4 20
Then in your structure, store the 'MSGADD' value, and when you want to access the string, use 'message[address]', starting at the defined address, rather than the pointer form.
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515527 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|