{The S-lang C Library Reference}: SLadd_intrinsic_variable

Next Previous Contents

## 102. SLadd_intrinsic_variable

Synopsis

  Add an intrinsic variable to the interpreter

Usage

  `int SLadd_intrinsic_variable (name, addr, type, rdonly)`

  > `

  >         char *name
  >         VOID_STAR type
  >         unsigned char type
  >         int rdonly

  > `

Description

  The `SLadd_intrinsic_variable` function adds an intrinsic variable called `name` to the interpeter. The second parameter `addr` specifies the address of the variable (cast to `VOID_STAR`). The third parameter, `type`, specifies the data type of the variable. If the fourth parameter, `rdonly`, is non-zero, the variable will interpreted by the interpreter as read-only.

  If successful, `SLadd_intrinsic_variable` returns zero, otherwise it returns `-1`.

Example

  Suppose that `My_Global_Int` is a global variable (at least not a local one):

  > `

  >         int My_Global_Int;

  > `

  It can be added to the interpreter via the function call

  > `

  >         if (-1 == SLadd_intrinsic_variable ("MyGlobalInt",
  >                                             (VOID_STAR)&My_Global_Int,
  >                                             SLANG_INT_TYPE, 0))
  >           exit (1);

  > `

Notes

  The current implementation requires all pointer type intrinsic variables to be read-only. For example,

  > `

  >         char *My_Global_String;

  > `

  is of type `SLANG_STRING_TYPE`, and must be declared as read-only. Finally, not that

  > `

  >        char My_Global_Char_Buf[256];

  > `

  is not a `SLANG_STRING_TYPE` object. This difference is very important because internally the interpreter dereferences the address passed to it to get to the value of the variable.
See Also

  `SLadd_intrinsic_function, SLadd_intrinsic_array`

}

Next Previous Contents