C-code and sprintf

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
pmr1
Flowcode V4 User
Posts: 12
Joined: Tue Apr 24, 2007 1:55 pm
Location: Edinburgh
Contact:

C-code and sprintf

Post 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

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: C-code and sprintf

Post 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.
Martin

pmr1
Flowcode V4 User
Posts: 12
Joined: Tue Apr 24, 2007 1:55 pm
Location: Edinburgh
Contact:

Re: C-code and sprintf

Post 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

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: C-code and sprintf

Post 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.
Martin

User avatar
Steve
Matrix Staff
Posts: 3427
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: C-code and sprintf

Post 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.

User avatar
Steve
Matrix Staff
Posts: 3427
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: C-code and sprintf

Post 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.

Huib Koppers
Posts: 63
Joined: Fri Oct 12, 2007 5:13 pm
Location: Netherlands
Been thanked: 1 time
Contact:

Re: C-code and sprintf

Post 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

Post Reply