Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

Validates a value as less than or equal to a specified maximum value.

Files

lib_def.h

Prototype

Arguments

val

Value to validate.

val_max

Maximum value to test.

Returned Value

DEF_OK

Value is less than or equal to maximum value;

DEF_FAIL

otherwise.

Required Configuration

None.

Notes / Warnings

DEF_CHK_VAL_MAX() avoids directly comparing any two values if only one of the values is negative since the negative value might be incorrectly promoted to an arbitrary unsigned value if the other value to compare is unsigned.

Validation of values is limited to the range supported by the compiler and/or target environment. All other values that underflow/overflow the supported range will modulo/wrap into the supported range as arbitrary signed or unsigned values. Therefore, any values that underflow the most negative signed value or overflow the most positive unsigned value supported by the compiler and/or target environment cannot be validated:

(    N-1       N     ]
( -(2   )  ,  2  - 1 ]
(                    ]

where N is the number of data word bits supported by the compiler and/or target environment. Note that the most negative value, -2^(N-1), is not included in the supported range since many compilers do not always correctly handle this value.

Example Usage

  • No labels