Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 31st, 2006, 1:00 PM   #1
JawaKing00
Newbie
 
Join Date: Sep 2004
Posts: 29
Rep Power: 0 JawaKing00 is on a distinguished road
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
JawaKing00 is offline   Reply With Quote
Old May 31st, 2006, 1:33 PM   #2
Adak
Hobby Coder
 
Join Date: May 2006
Posts: 59
Rep Power: 0 Adak is an unknown quantity at this point
I don't understand why you don't just pass the array's base address (the array name itself), to the function?

Adak
Adak is offline   Reply With Quote
Old May 31st, 2006, 1:44 PM   #3
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 Narue is on a distinguished road
>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.
Narue is offline   Reply With Quote
Old May 31st, 2006, 2:10 PM   #4
JawaKing00
Newbie
 
Join Date: Sep 2004
Posts: 29
Rep Power: 0 JawaKing00 is on a distinguished road
Thanks I'll try that out. I figured it would be something dumb like that.
JawaKing00 is offline   Reply With Quote
Old May 31st, 2006, 2:19 PM   #5
JawaKing00
Newbie
 
Join Date: Sep 2004
Posts: 29
Rep Power: 0 JawaKing00 is on a distinguished road
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.
JawaKing00 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:43 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC