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