Back to Index

Definition: macro Name(arg1, ..., &outVar, ...) { ... } — Allowed: identifiers for parameters; call-site passes expressions for inputs and assignable targets for output params; Not allowed: literals or non-assignable expressions in output positions.

Defines a compile-time macro. Calls expand inline with positional arguments. Use & to mark output parameters at the call site.

Control-flow note: macros are expanded inline. return or next inside a macro affect the caller context, not just the macro body.

Example

macro DryRunFault(w, dryLevel, pump, delayMs, clearEdgeIn, &dryFlag) {
  _state = 0;
  if (ton("_ton", w<dryLevel && pump, delayMs)) {
    dryFlag = 1;
    out(1) = 0;
    out(2) = 0;
    out(3) = 0;
  }
  if (p_edge(in(clearEdgeIn)) && w>=dryLevel) {
    dryFlag = 0;
    t_reset("_ton");
  }
}

DryRunFault(w, DRY, pump, BDELAY, 8, &dry);

Notes: identifiers starting with _ inside a macro are auto-renamed per expansion; timer IDs like ton("_ton", ...) are prefixed to avoid collisions.