function with variable parameters

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

function with variable parameters

跳至解决方案
1,228 次查看
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

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
861 次查看
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 项奖励
回复
5 回复数
861 次查看
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 项奖励
回复
862 次查看
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 项奖励
回复
861 次查看
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 项奖励
回复
861 次查看
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 项奖励
回复
861 次查看
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 项奖励
回复