![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2004
Posts: 29
Rep Power: 0
![]() |
Arrays, Pointers, and Constants
I am writing some code that will display a bitmap image to a display. The bitmap is stored as a very large constant array of bytes. I want to write a function that I can pass the pointer to the array to and have the function write it to the display. Currently, though, I am getting a compiler warning saying "passing arg 1 of `DisplayGraphicScreen' discards qualifiers from pointer target type"
Here is what I have: in main.c void main (void)
{
//stuff
DisplayGraphicScreen(logo1, sizeof(logo1));
//more stuff
}The function VOID DisplayGraphicScreen ( INT8U *MyScreen, INT16U ArraySize )
{
INT8U i;
DisplayChar(0x1F);
DisplayChar(0x28);
DisplayChar(0x66);
DisplayChar(0x11);
for (i=0; i < ArraySize; i++)
{
DisplayChar(MyScreen[i]);
}
}The array const INT8U logo1[4101]=
{
0x00,
0x01,
0x10,
0x00,
0x01,
// a ton more entries
};When I use the code that is in the function by itself, it displays fine. But when I try to pass the array to the function I get that compiler warning and a bunch of garbage on the screen. Is there something I am doing wrong passing that array to the function? Any help would be greatly appreciated. Thanks, Andy |
|
|
|
|
|
#2 |
|
Hobby Coder
Join Date: May 2006
Posts: 59
Rep Power: 0
![]() |
I don't understand why you don't just pass the array's base address (the array name itself), to the function?
Adak |
|
|
|
|
|
#3 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 4
![]() |
>void main (void)
main returns int. >VOID DisplayGraphicScreen ( INT8U *MyScreen, INT16U ArraySize ) logo1 is defined as an array of const data, but you're passing it as if it were not const. That's generally not a good idea: VOID DisplayGraphicScreen ( const INT8U *MyScreen, INT16U ArraySize )
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Sep 2004
Posts: 29
Rep Power: 0
![]() |
Thanks I'll try that out. I figured it would be something dumb like that.
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Sep 2004
Posts: 29
Rep Power: 0
![]() |
Ok I knew it was going to be something stupid.
The index variable for the FOR loop is declared as an INT8U, and the value it's compared against is an INT16U, and that is rarely less than 255, so the FOR statement was always true and only getting the first 255 entries in the array. I changed i to a 16 bit variable, and now things work great. Thanks for the input. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|