[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: |
Dave Hylands |
Subject: |
RE: [avr-gcc-list] why the pointer get a error address? |
Date: |
Sat, 14 Feb 2004 08:44:01 -0800 |
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
>
>