function with variable parameters

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

function with variable parameters

Jump to solution
847 Views
euge
Contributor I

Hi

is it possible create a function with variable parameters on CW6.3 SE ?

I did a function    void SendUart(byte *pbFrase,byte bQUart ) and and works perfectly

With  a MCF51QE128 if If I transmit  SendUart("Hello",2 ) I receive OK on a serial terminal.

I do void SendUart(byte *pbFrase,byte bQUart,... ) to acept variable parameters CW6.3 doesn`t give errors

but not work well.

When I debbug the function don´t pass well the parameters.

Maybe U have another way to define these functions.
ia there some experience in this area?

Eugenio

Labels (1)
Tags (1)
0 Kudos
1 Solution
480 Views
CrasyCat
Specialist III

Hello

 

   Just an additional comment on using functions with variable parameters.

   When you are invoking such a function it is mandatory to have a prototype of the function specified before you actually call it.

 

  Often parameter passing scheme for normal function and function with variable parameter differs a bit.

  So you have to use a function prototype before you invoke such a function.

 

CrasyCat

View solution in original post

0 Kudos
5 Replies
480 Views
kef
Specialist I
  • is it possible create a function with variable parameters on CW6.3 SE ?

Yes, of course. What you know about stdarg.h, va_arg and va_start?

http://www.cplusplus.com/reference/clibrary/cstdarg/va_arg/

 

0 Kudos
481 Views
CrasyCat
Specialist III

Hello

 

   Just an additional comment on using functions with variable parameters.

   When you are invoking such a function it is mandatory to have a prototype of the function specified before you actually call it.

 

  Often parameter passing scheme for normal function and function with variable parameter differs a bit.

  So you have to use a function prototype before you invoke such a function.

 

CrasyCat

0 Kudos
480 Views
euge
Contributor I

Thanks for your response, now the function works well.
Maybe you can ask another question, When I include <stdio.h> the printf function should work, but it is not accepted by the compiler.
printf does not change color in the editor and it does not work.
That thing I have not taken into account?

Eugenio

0 Kudos
480 Views
kef
Specialist I

Color in IDE doesn't matter. Even if it changes, sometimes it changes only after successfull build.

Printf may not work without output driver routine (look into library source or search examples folders for projects that are using printf). You may try sprintf, which also takes variable number of arguments, but doesn't depend on output routines.

0 Kudos
480 Views
euge
Contributor I

 

Thanks for your help
Finally I found the problem

I describe below in case anyone needs it.
To use functions like sprintf , printf  and others  besides  include <Stdio.c>  you need to add the  printf.c file in your project
The functions started to work when I added  printf.c in Libs next to the  MCF51QE128.C  and console_io_cf.c

console_io_cf.c was added automatically when I create the project and I´m not sure if it is important

 

printf.c is in 

C:\Programs Files\Freescale\CodeWarrior for Microcontrollers V6.3\ColdFire_Support\ewl\EWL_C\src\printf.c.

Best Regards

Eugenio


0 Kudos