07 03 default values
Some P4 types define a “default value,” which can be used to automatically initialize values of that type. The default values are as follows:
- For
int,bit<N>andint<N>types the default value is 0. - For
boolthe default value isfalse. - For
errorthe default value iserror.NoError(defined in core.p4) - For
stringthe default value is the empty string"" - For
varbit<N>the default value is a string of zero bits (there is currently no P4 literal to represent such a value). - For
enumvalues with an underlying type the default value is 0, even if 0 is actually not one of the named values in the enum. - For
enumvalues without an underlying type the default value is the first value that appears in theenumtype declaration. - For
headertypes the default value isinvalid. - For header stacks the default value is that all elements are invalid
and the
nextIndexis 0. - For
header_unionvalues the default value is that all union elements are invalid. - For
structtypes the default value is astructwhere each field has the default value of the suitable field type – if all such default values are defined. - For a
tupletype the default value is atuplewhere each field has the default value of the suitable type – if all such default values are defined.
Note that some types do not have default values, e.g., match_kind, set
types, function types, extern types, parser types, control types,
package types.