Skip to main content

Difference between Procedure, Function and Impure Function

Criteria Procedure Function Impure Function
Purpose Perform tasks without returning a value. Return a value from a calculation. Produce an unpredictable value or one that depends on external factors.
Arguments Can have input and/or output arguments. Can have input arguments only. Can have input arguments only.
Return Value Does not return a value (void). Returns a value from a calculation. Returns a value from a calculation.
Usage Used to organize tasks or operations. Used for calculations or data processing. Used when the function's result depends on external factors.
Example vhdl procedure SetFlag(flag: out boolean); vhdl function Add(a, b: integer) return integer; vhdl function RandomNumber return integer;
Synthesis Can be synthesized if it is deterministic and synchronous. Can be synthesized if it is deterministic and synchronous. Not suitable for synthesis because the result is unpredictable or depends on external factors.