2014-08-08 02:41 AM
Hi community,
I am having trouble using the sprintf function to convert a variable into a string. It compiles just fine if I dochar string[11];
sprintf(string, ''23'');
And I can see the numer 23 in ''string'' while debugging.
But just using a variable instead of the number, like
int data = 23;
sprintf(string, data);
throws these errors:
undefined reference to `__HEAP_END' SPC563Mxx OS-Less Test Application line 37, external location: \data\distribution\free-entry-toolchain-v4.6.2.1\gcc-4.6.x\libhtcos\ppc-vle\libos_sbrk.c C/C++ Problem
undefined reference to `__HEAP' SPC563Mxx OS-Less Test Application line 0, external location: c:\spc5studio\eclipse\plugins\com.st.tools.spc5.tools.hightec_1.0.0.201306281422\hightec\ppc-ht-eabi\lib\vle\libos.a(libos_sbrk.o) C/C++ Problem
undefined reference to `__HEAP' SPC563Mxx OS-Less Test Application line 42, external location: \data\distribution\free-entry-toolchain-v4.6.2.1\gcc-4.6.x\libhtcos\ppc-vle\libos_sbrk.c C/C++ Problem
I would suspect some compiler/linker issues. Does anybody have any ideas?
Best regards
Henrik
#babycare.com
2014-08-08 08:02 AM
Hello Henrik,
it is linked to the compiler.the compiler does not provide an implementation of ''sbrk''.if you copy-paste this following code at the top of main.cit should compile.#include <errno.h>#include ''stdio.h''void *sbrk(size_t incr) { extern uint8_t __heap_base__; extern uint8_t __heap_end__; static uint8_t *p = &__heap_base__; static uint8_t *newp; newp = p + incr; if (newp > &__heap_end__) { errno = ENOMEM; return (void *)-1; } return p = newp;}....................char string[11];
int data = 23; sprintf(string, ''%d'', data);Could you try this ?Anyway , we are opening a ticket for this. Best regards Erwan2014-08-08 08:25 AM
Hello Erwan,
it compiles and sprintf seems to work like it should, afer a quick test. Thank you very much for the quick help! Best regards Henrik2014-08-22 10:39 AM