|
|
View previous topic :: View next topic |
Author |
Message |
SeeCwriter
Joined: 18 Nov 2013 Posts: 160
|
Pointers to an array |
Posted: Mon Nov 30, 2020 10:41 am |
|
|
Can I create an array of 32-bit integers and assign that to a pointer? I don't have hardware to test this right now, and when I tried it a few years ago it didn't work. It compiled but the program didn't do what I wanted.
Example:
Code: |
signed int32 *pData[];
const signed int32 mydata[] =
{
0x01000002,
0x02000001,
0x03000046,
0x05000390,
0x05000000,
0x06002F4A,
0x0700054D,
0x08C9BEFF,
0x09573FFF,
0x0A002047,
0x0B0F8061,
0x0F000081,
0x04200000
};
void main()
{
byte len = sizeof(mydata) >> 2;
pData = mydata;
Dosomething(pData, len);
}
void Dosomething( int32 *d, byte num )
{
}
|
I'm using v5.097 of PCWH and a 12LF1552 pic. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Mon Nov 30, 2020 11:51 am |
|
|
Historically, the problem would have been this one word. 'Const'.
The problem is that the PIC is a Harvard architecture processor. On this
the RAM, and program memory are in different memory spaces. Const
puts the variable into the program memory space. Result a RAM pointer
won't actually point to it....
Now you can use ROM instead of const, which tells the compiler to store
the data so a ROM * pointer can be constructed to it. However you do have
to declare your function so it expects a ROM * pointer.
If you look at my SSD1306 driver in the code library this uses ROM *
pointers, so you can see how these can be used. Beware though that
CCS 5.096 has an issue with these (fixed in 5.097, and OK on earlier
releases). |
|
|
SeeCwriter
Joined: 18 Nov 2013 Posts: 160
|
|
Posted: Mon Nov 30, 2020 12:04 pm |
|
|
I will check it out. Thanks. |
|
|
|
|
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
|