avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] PGM_S, prog_uchar macro oddities


From: J.C. Wren
Subject: [avr-gcc-list] PGM_S, prog_uchar macro oddities
Date: Sat, 19 Oct 2002 18:34:12 -0400

        The following code example perplexes me.  The test_2 version works as 
I'd
expect, and produces code as I'd expect.  The test_1 sample works, but
produces some weird code.  Why is it copying the constant array in memory on
to the stack?  That's indicative of dynamic variable behavior.  Is there no
way to create a static array in code space and reference it as such?

        I don't want to use it as a string, because sizeof() returns the size of
the pointer, not the string, and strlen() will terminate if there is a
binary 0 in data (which is quite likely).  Not to mention the encoding is a
lot harder to read with all the escapes and such.

        What am I missing here?

        --John

... GCC version ...

Reading specs from /usr/local/avr/lib/gcc-lib/avr/3.3/specs
Configured with:
../configure --prefix=/usr/local/avr --target=avr --enable-languages=c,c++ -
-disable-nls
Thread model: single
gcc version 3.3 20021019 (experimental)

... Compiled with ...

/usr/local/avr/bin/avr-gcc -W -Wall -mmcu=atmega8 -Os -g -c t.c
/usr/local/avr/bin/avr-objdump -dSst t.o >t.lst

... The program ...

#include <avr/pgmspace.h>
#include <avr/io.h>

void test_1 (void)
{
   const prog_uchar arr [] = {0xca, 0xfe, 0xba, 0xbe, 0xde, 0xad, 0xbe,
0xef};
   unsigned int i;

   for (i = 0; i < sizeof (arr); i++)
      UDR = arr [i];
}

void test_2 (void)
{
   PGM_P arr = "\xca\xfe\xba\xbe\xde\xad\xbe\xef";
   unsigned int i, l;

   for (i = 0, l = strlen_P (arr); i < l; i++)
      UDR = arr [i];
}


avr-gcc-list at http://avr1.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]