I tried different example:
char buffer[80];
char one[]={'a','s','x'};
char two[]={'a','s','x'};
AD1. snprintf(buffer,sizeof(buffer)," string: %2s string: %2s", one,two);
I think problem is related to '\0' char at end of string;
It looks like snprintf first searches '\0' in buffer[80], than appends
string one, then string two. If buffer doesn't contain '\0' wirting
is skipped.  
AD2.(malloc)
Example:
char __attribute__(section((.noinit))) test[3];
char*  malloc_inserter;
test[0]='Z';
malloc_inserter = (char*) malloc(3);
*malloc_inserter = 'A';

Now test[0] not equals 'Z'

Problem is that malloc uses begining of .noinit section for heap storage, what 
compiler is not aware of, and allocates forced variables to the same area.
There should be way around, because Atmel avrgcc does it fine.
For example use  reserve(.heap) int main(){}
ROBERT

On Tuesday 18 of November 2003 00:52, Chris Liechti wrote:
> Robert Seczkowski wrote:
> > snprintf doesn't work as snprintf(buffer,10," %2s ",string).
> > It does nothing.
>
> it works for me. that snippet (with appropriate init, not shown):
>
> char buffer[80];
> snprintf(buffer, sizeof(buffer), "number: %d string: %s", 1234,"hello");
> puts(buffer);
>
> outputs over the serial port:
> """
> number: 1234 string: hello
> """
>
> > Also malloc reserves begining  of .noinit section for heap storage
> > whereas compiler doesn't know about it and variables declared to be in
> > .noinit section are overitten!
>
> i usualy dont use malloc.. but i did a quick test:
>
> i haev a global:
> int global;
>
> and locals in main():
>      char * xa;
>      char * xb;
>
>      //init snipped
>
>      xa = malloc(10);
>      xb = malloc(10);
>      printf("xa: 0x%04x\n", xa);
>      printf("xb: 0x%04x\n", xb);
>      printf("global: 0x%04x\n", &global);
>
> output:
> xa: 0x020e
> xb: 0x021a
> global: 0x020a
>
> looks fine, xa starts after the global, ad xb starts exactly 12 bytes
> later. so malloc seems to have some overhead, but it works.
> and just to be sure:
>
>      memset(xa, 0, 10);
>      memset(xb, 0, 10);
>      snprintf(xb, 10, "%d %d", 9876, 543);
>      snprintf(xa, 10, "%d %d", 1234, 567);
>      puts(xa);
>      puts(xb);
>
> outputs:
> """
> 1234 567
> 9876 543
> """
>
> all compiled with CFLAGS = -mmcu=${CPU} -O2 -Wall -g
> cvs version of libc, some weeks old msp430-gcc 3.2.3
>
> chris
>
>
>
> -------------------------------------------------------
> This SF. Net email is sponsored by: GoToMyPC
> GoToMyPC is the fast, easy and secure way to access your computer from
> any Web browser or wireless device. Click here to Try it Free!
> https://www.gotomypc.com/tr/OSDN/AW/Q4_2003/t/g22lp?Target=mm/g22lp.tmpl
> _______________________________________________
> Mspgcc-users mailing list
> Mspgcc-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users

-- 
Regards
Robert Seczkowski 
robert.seczkow...@sz.onet.pl
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\

Reply via email to