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

Version 1 Next »

Validates a value as greater than or equal to a specified minimum value.

Files

lib_def.h

Prototype

          DEF_CHK_VAL_MIN(val, val_min);

Arguments

val

Value to validate.

val_min

Minimum value to test.

Returned Value

DEF_OK

Value is greater than or equal to minimum value;

DEF_FAIL

otherwise.

Required Configuration

None.

Notes / Warnings

DEF_CHK_VAL_MIN() 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

          #define  CFG_VAL           -1
           
          #if     (DEF_CHK_VAL_MIN(CFG_VAL, 0u) != DEF_OK)  /* Signed CFG_VAL NOT promoted to unsigned. */
          #error  "CFG_VAL must be >= 0"
          #endif
  • No labels