Page 1 of 1

C-code and sprintf

Posted: Mon Sep 06, 2010 3:29 pm
by pmr1
I have a C-code macro thus in FCV4.1

C-code macro

#include <stdio.h>

FCL_TEMP=sprintf(FCL_TEMP,"%d-150",FCL_NUMB);
return(FCL_TEMP);

and compiler, when compile to chip is select returns an

C:\PROGRA~1\MATRIX~1\FLOWCO~2\BoostC\include\stdio.h(17): error: missing right paren
C:\PROGRA~1\MATRIX~1\FLOWCO~2\BoostC\include\stdio.h(17): error: general error
C:\PROGRA~1\MATRIX~1\FLOWCO~2\BoostC\include\stdio.h(17): error: variable name expected
C:\PROGRA~1\MATRIX~1\FLOWCO~2\BoostC\include\stdio.h(17): error: general error
C:\PROGRA~1\MATRIX~1\FLOWCO~2\BoostC\include\stdio.h(17): error: variable name expected
C:\PROGRA~1\MATRIX~1\FLOWCO~2\BoostC\include\stdio.h(17): error: general error
C:\teaching\b38DB\PWM\motor2.c(1060): error: missing right paren
C:\teaching\b38DB\PWM\motor2.c(1060): error: general error
C:\teaching\b38DB\PWM\motor2.c(1060): error: variable name expected
C:\teaching\b38DB\PWM\motor2.c(1060): error: general error
C:\teaching\b38DB\PWM\motor2.c(1060): error: variable name expected
C:\teaching\b38DB\PWM\motor2.c(1060): error: general error
C:\teaching\b38DB\PWM\motor2.c(1060): error: failure

Would appreciate some guidance as to what I'm doing wrong

Regards
Paul

Re: C-code and sprintf

Posted: Mon Sep 06, 2010 4:18 pm
by medelec35
Hiya pmr1. Take a look here:
http://www.matrixmultimedia.com/mmforum ... 90&p=20249
Not sure if applies to both flowcode4 and arm, or just arm?

Hope that helps you.

Re: C-code and sprintf

Posted: Tue Sep 07, 2010 2:18 pm
by pmr1
Hi Medelec35,

Thanks for the information. My compile target is PIC18F452
That's interesting because sprintf is listed in the boostC compiler manual; that's why I used it. Also when I requested a return value of string pointer the macro ( function ) it constructed in the C listed it as returning void :-

void FCM_number_to_string(char* FCR_RETVAL, char FC_NUMBER_TO_STRING_SZ_RETURN, short FCL_NUMB)
{
//converts number to string to enable display

//Local variable definitions
#define FC_NUMBER_TO_STRING_SZ_TEMP 20
char FCL_TEMP[FC_NUMBER_TO_STRING_SZ_TEMP];
*/

#include <stdio.h>

FCL_TEMP=sprintf(FCL_TEMP,"%d-150",FCL_NUMB);
return(FCL_TEMP);



}

Regards
Paul

Re: C-code and sprintf

Posted: Tue Sep 07, 2010 8:37 pm
by medelec35
From the posts I am reading, sprintf is only available for use with arm and not flowcode4. Then I would assumed sprintf is in boostc manual since arm also uses boostc.
So commands in boostc are not necessary compatible will all version of flowcode.

Re: C-code and sprintf

Posted: Wed Sep 08, 2010 6:54 am
by Steve
The ARM version of Flowcode does not use BoostC - this is only used by the PICmicro version. But BoostC does have a "sprintf" command, although the format of this may be different to the "sprintf" used by the ARM compiler.

Re: C-code and sprintf

Posted: Wed Sep 08, 2010 7:07 am
by Steve
A bit more on this...

The original error is because the "#include <stdio.h>" line is in a C icon and therefore is placed within a C function. You will need to include this outside of the function. To do this, put this line in the top box of the "supplementary code" window.

The to call this function, use "sprintf(FCL_TEMP,"%d-150",FCL_NUMB);" in a C icon somewhere.

I have tested this and it compiles ok. But I have not tested the program actually works on hardware. Note it will not simulate because it is user C code.

Re: C-code and sprintf

Posted: Wed Sep 08, 2010 11:38 am
by Huib Koppers
Hello Steve,

I have tried also the "sprintf" function and the compiling part goes well, but the assembling part doesn't even if i put "#include <stdio.h>" into a C box in the top of the program.
This is the assembler result.

Launching the linker/assembler...
C:\Program Files\Matrix Multimedia\Flowcode ARM V4\Tools\MX_bats\arm7link.bat "Flowcode2" at91sam7s256

G:\ARM\FlowCode projects\OlimexSAM7P256_Projects_FCv4>arm-elf-gcc -mcpu=arm7tdmi -O2 -Wall "C:\PROGRA~1\MATRIX~1\FLOWCO~3\Tools\MX_bats\..\Global\Cstartup.o" "Flowcode2".o -lm -aln="Flowcode2".lst --output "Flowcode2".elf -nostartfiles -T"C:\PROGRA~1\MATRIX~1\FLOWCO~3\Tools\MX_bats\..\Global\at91sam7s256-ROM.ld" -L"C:\PROGRA~1\MATRIX~1\FLOWCO~3\Tools\MX_bats\..\arm-elf\lib" -L"C:\PROGRA~1\MATRIX~1\FLOWCO~3\Tools\MX_bats\..\lib\gcc\arm-elf\4.0.1"
C:\PROGRA~1\MATRIX~1\FLOWCO~3\Tools\MX_bats\..\arm-elf\lib\libc.a(makebuf.o): In function `__smakebuf':
makebuf.c:(.text+0x44): undefined reference to `_fstat_r'
C:\PROGRA~1\MATRIX~1\FLOWCO~3\Tools\MX_bats\..\arm-elf\lib\libc.a(stdio.o): In function `__sread':
stdio.c:(.text+0x1c): undefined reference to `_read_r'
C:\PROGRA~1\MATRIX~1\FLOWCO~3\Tools\MX_bats\..\arm-elf\lib\libc.a(stdio.o): In function `__swrite':
stdio.c:(.text+0x78): undefined reference to `_lseek_r'
stdio.c:(.text+0x9c): undefined reference to `_write_r'
C:\PROGRA~1\MATRIX~1\FLOWCO~3\Tools\MX_bats\..\arm-elf\lib\libc.a(stdio.o): In function `__sseek':
stdio.c:(.text+0xc0): undefined reference to `_lseek_r'
C:\PROGRA~1\MATRIX~1\FLOWCO~3\Tools\MX_bats\..\arm-elf\lib\libc.a(stdio.o): In function `__sclose':
stdio.c:(.text+0xf8): undefined reference to `_close_r'

Error returned from [arm-elf-gcc.exe]

Return code = 1

Assembleren mislukt vanwege de foutmelding:

Regards Huib