Same function, different parameters

Same function, different parameters

Post by Peteris Krumin » Fri, 27 Jun 2003 08:56:48



Hello,

 I am wondering how this could be done the best:
  for example, functions (printf, vprintf), (fprintf, vfprintf)
  one of the pair takes ..., the other va_list as the last parameter.
  How is a change in the source file done? If some improvements are made to
  the first function in the pair the same should be done in the second, so
  the same source has to be typed twice.

 Is there a smarter way to have two functions where one of them takes
 ... as a parameter the second va_list, and not to have change source in
 two both if they do almost the same?

P.Krumins

 
 
 

Same function, different parameters

Post by David Schwart » Fri, 27 Jun 2003 09:08:18



Quote:>  I am wondering how this could be done the best:
>   for example, functions (printf, vprintf), (fprintf, vfprintf)
>   one of the pair takes ..., the other va_list as the last parameter.
>   How is a change in the source file done? If some improvements are made
to
>   the first function in the pair the same should be done in the second, so
>   the same source has to be typed twice.

    The function that takes variable arguments calls the va_list function.
For example:

int SomeFunctionVA(const char *c, va_list ap)
{
 // the real code goes here

Quote:}

int SomeFunction(const char *c, ...)
{
 va_list ap;
 va_start(ap, c);
 int ret=SomeFunctionVA(c, ap);
 va_end(ap);
 return ret;

Quote:}

    DS

 
 
 

Same function, different parameters

Post by Peteris Krumin » Fri, 27 Jun 2003 09:28:13






> [...]

>     The function that takes variable arguments calls the va_list
>     function.
> For example:

> int SomeFunctionVA(const char *c, va_list ap)
> {
>  // the real code goes here
> }

> int SomeFunction(const char *c, ...)
> {
>  va_list ap;
>  va_start(ap, c);
>  int ret=SomeFunctionVA(c, ap);
>  va_end(ap);
>  return ret;
> }

Thanks!

P.Krumins

 
 
 

1. passing parameter to shell function as in the normal unix commands (not positional parameter)

Hi,

I have a function defined in in .profile which accepts three
parameters.

function myfn
{
var1=$1
var1=$3
var1=$3

I am wondering, whether the function can be invkoded as

"myfun -c var1 -d var2 -e var3"

The reason, I would prefer this method, because I don't have to know
the order of the parameters and optionally I can ignore one or more of
the parameter and set the default value, inside the program if needed.

note: I know, it can be invoked as "myfun var1 var2 var3"
      I am using ksh under AIX 5.2

Thanks,
Prince.

2. X terminal

3. Different Functions of Same Name in Different Libs

4. How to clean up directories

5. Does Linux need different cpio parameters to work??

6. Recovering files from a Newfs'd partition

7. two hard disks, different parameters same drives

8. Intermittent problems.....

9. Many bonding interface with different module parameters

10. Qt SIGNAL / SLOT question (different parameter lists)

11. kernel function parameter - crash

12. function call with variable nb. of parameters

13. passing parameters with spaces to shell function