next up previous contents
Next: Command variables Up: Variables Previous: Numeric variables   Contents


Common idioms

The example above shows an idiom frequently used in packet construction scripts: a variable is set to a default value in a macro, and can then be superseded by assignments passed as a macro parameter.

Similarly, variables without default value, or with a global default, can be set using the same syntax.

While this idiom makes effective use of the rather limited variable handling capabilities of tcsim, and is syntactically elegant, it is not without dangers: because tcsim variables are always global, variables that are not explicitly reset to a default value will retain their value also after the macro in which they are set.

Example:

#define foo(params) \
  $value=0 /* local default */ \
  params $value

send foo($value=8)
send foo()

yields

08
00

but

$value=0 /* global default */

#define foo(params) \
  params $value

send foo($value=8)
send foo()

yields

08
08



Martin A. Brown 2003-11-06