[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-gcc-list] why the pointer get a error address?
From: |
whiteman |
Subject: |
RE: [avr-gcc-list] why the pointer get a error address? |
Date: |
Sun, 15 Feb 2004 15:14:1 +0800 |
Hi,Dave Hylands & Fabian braun!
I have tried your suggestions, but didn't realize what I wanted. In the past, I
used C51. I can defined a pointer that can
point to any array in program space.
eg:
uchar code* character_pnt;
uchar code a_array[]={
0x31,0x01,0x21,0x21,0x11,0x30,0x30,0x21,0x31,0x31,0x00,0x00,0x04,0x00,
};
uchar code b_array[]={
1,2,3,4,5,6
};
void func1()
{
character_pnt = a_array;
;
;
character_pnt = b_array;
;
;
}
All operation is ok and get the correct value. I thought there was any way
realize my attempt,but how can I do that?
======= 2004-02-14 08:44:00=======
>I'm not sure why it isn't working, But I thought I'd make a comment on the
>const stuff.
>
> const char *p1; declares a pointer to a constant character.
>
>When reading pointer stuff, start at the * and go left.
>
> char const *p2; is the same thing (char const and const char are
> synnonomous).
>
> char * const p3; declares a constant pointer to a character
> (this one has to be initialized);
>
> const char * const p4; delcares a constant pointer to a constant
> character (also has to be initalized when declared).
>
>This little sample is perfectly fine:
>
> const char *s;
>
> s = "str";
>
> while ( *s != 0 )
> {
> ... Do something with *s ...
>
> s++;
> }
>
>But you're not allowed to do this:
>
> const char *s;
>
> s = "str";
>
> *s = 'S';
>
>So, it's important to differentiate between the pointer and the stuff the
>pointer points at.
>
>--
>Dave Hylands
>Vancouver, BC, Canada
>http://www.DaveHylands.com/
>
>
>> -----Original Message-----
>> From: address@hidden
>> [mailto:address@hidden On Behalf Of Fabian Braun
>> Sent: Saturday, February 14, 2004 12:22 AM
>> To: address@hidden
>> Subject: AW: [avr-gcc-list] why the pointer get a error address?
>>
>>
>>
>> Hy whiteman
>>
>> As far as I know: If you declare a constant value you also
>> have to define its value in the same line eg. (const char x =
>> 5;). I'm not very sure, could also be compiler dependent but
>> I learned that you never can assing a value to a const
>> variable in the programme like (charcter_pnt = test_array;).
>>
>> Might be a fault :-)
>>
>> /FaB
>> -----Ursprüngliche Nachricht-----
>> Von: address@hidden
>> [mailto:address@hidden Im > Auftrag von
>> whiteman
>> Gesendet: Samstag, 14. Februar 2004 02:28
>> An: avr-gcc-list
>> Betreff: [avr-gcc-list] why the pointer get a error address?
>>
>> hi,all!
>> I defined a array in program space and a pointer to this array.
>> eg:
>>
>>
>> uint8_t test_array[] PROGMEM = {
>> 1,2,3,4,5,6,7
>> };
>> const prog_char *character_pnt;
>>
>> void main(void)
>> {
>> charcter_pnt = test_array;
>> ;
>> ;
>> }
>>
>> but when I simulated with avr_studio, I found the
>> "character_pnt" get a error address,The "*character_pnt"
>> isn't equal to 1.why?
>>
>>
>> Regards
>>
>> whiteman
>> address@hidden
>> 2004-02-14
>>
>>
>>
>>
>> _______________________________________________
>> avr-gcc-list mailing list
>> address@hidden
>> http://www.avr1.org/mailman/listinfo/avr-gcc-list
>>
>>
>>
>>
>> _______________________________________________
>> avr-gcc-list mailing list
>> address@hidden
>> http://www.avr1.org/mailman/listinfo/avr-gcc-list
>>
>>
>
>
>_______________________________________________
>avr-gcc-list mailing list
>address@hidden
>http://www.avr1.org/mailman/listinfo/avr-gcc-list
= = = = = = = = = = = = = = = = = = = =
Regards
whiteman
address@hidden
2004-02-15