On Tuesday 13 May 2008 05:36:25 am Marc Wetzel wrote: > Hi, > > I just found out the hard way, that the allocation of prog_mem variables > is not location independend. > > So, if you alloc a variable outside of a function, e.g. in the > "standard" top area of your c-file, everything is working as expected. > But if you declare it inside a function, it does not work (as expected). > > Working Example: > -- > const prog_mem char teststring[]= "Teststring"; > > void * test(void) { > fprintf_P(uart, teststring); > } > -- > > Non-Working Example (but compiling fine): > -- > void * test(void) { > const prog_mem char teststring[]= "Teststring"; > fprintf_P(uart, teststring); > } > -- > > Is this the intended behaviour? > What cause is here the trigger?
I'm not eaxctly sure why they behave differently, but the latter causes teststring[] to be allocated in the .data section instead of .progmem. So, a regular fprintf() would work. You might want to use PSTR() and the other pgmspace.h macros instead. For your example it would be: void * test(void) { PGM_P teststring = PSTR("Teststring"); fprintf_P(uart, teststring); } Or even: void * test(void) { fprintf_P(uart, PSTR("Teststring")); } These work as expected. -mark > > TIA > Marc > > > _______________________________________________ > AVR-GCC-list mailing list > AVR-GCC-list@nongnu.org > http://lists.nongnu.org/mailman/listinfo/avr-gcc-list _______________________________________________ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list