next up previous contents index
Next: System's options Up: Examples of headers Previous: Use of optional arguments   Contents   Index


Use of variable and unused arguments

The module demohead3 shows the use of variable arguments. It includes also one unused argument, Win, which is a pointer to a scalar. The type of this argument should be Wframe, a pointer to a window structure (See the Volume two: ``MegaWave2 System Library'' about the Wdevice library). But Wframe is not a MegaWave2 object, therefore this type cannot be used in the header. By casting the variable in the call to demohead3, one can define Win as a pointer to any scalar.

Notice that the variable Output is of type Cimage *; it is therefore a pointer of pointer. Why ? this is not requested by the MegaWave2 header, but by the last instruction
*Output = Input;
This instruction changes the address pointed out by *Output. If Output was of type Cimage, the instruction
Output = Input;
would change the address inside the module function only, not outside. With Output of type Cimage, the only solution is to copy the content of Input into Output (using the function mw_copy_cimage()).

 
/*----------------------------- MegaWave Module -----------------------------*/
/* mwcommand
  name = {demohead3};
  version = {"1.0"};
  author = {"Jacques Froment"};
  function = {"Demo of MegaWave2 header - #3: variable and notused arguments -"};
  usage = {
    A->Input            "Input (could be a cimage)",
    ...<-Output         "Output (copy of the input)",
    notused -> Win      "Window (internal use only)" 
          };
*/
/*---------------------------------------------------------------------------*/

#include <stdio.h>

/* Include always the MegaWave2 Library */
#include "mw.h"

/* Include the window since we use windows facility */
#include "window.h" 

void demohead3(Input,Output,Win)

Cimage Input;
Cimage *Output;  /* Here we define *Output since the function changes the  */
                 /* pointer value (we set bellow *Output = Input)          */

char *Win;       /* Should be "Wframe *Win" for a MegaWave2 window         */
                 /* BUG: We cannot use other type than scalar or MegaWave2 */
                 /* Don't forget to cast before the function call          */
{
  if (Win != NULL)
    {
      printf("Library call: passing Window ptr\n");
      /*
         ...
      */
    }
  else printf("Command call: no Window ptr\n");

  if (*Output == NULL) printf("No output requested !\n");
  else 
    *Output = Input;  
}


next up previous contents index
Next: System's options Up: Examples of headers Previous: Use of optional arguments   Contents   Index
mw 2004-05-05