a variable of an integer type that doesn't have a length modifier.
The appropriate conversions from and to
.IR intmax_t ,
-and the appropriate range checkings,
-are used as explained in the notes section above:
+and the appropriate range checks,
+are used as explained in the notes section above.
.PP
.EX
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>
-
int
main (void)
{
intmax_t tmp;
/* Scan the number from the string into the temporary variable */
+
sscanf(str, "%jd", &tmp);
/* Check that the value is within the valid range of suseconds_t */
- if (tmp < -1 || tmp > 1000000) {
- fprintf(stderr, "Scaned value might overflow!\en");
+
+ if (tmp < \-1 || tmp > 1000000) {
+ fprintf(stderr, "Scanned value outside valid range!\en");
exit(EXIT_FAILURE);
}
- /* Copy the value to the suseconds_t variable 'us' */
+ /* Copy the value to the suseconds_t variable \(aqus\(aq */
+
us = tmp;
- /* Even though suseconds_t can hold the value -1,
- it represents an error code */
+ /* Even though suseconds_t can hold the value \-1, this isn\(aqt
+ a sensible number of microseconds */
+
if (us < 0) {
- fprintf(stderr, "Scanned an error code!\en");
+ fprintf(stderr, "Scanned value shouldn\(aqt be negative!\en");
exit(EXIT_FAILURE);
}
/* Print the value */
- printf("There are %jd us in half a second.\en", (intmax_t) us);
+
+ printf("There are %jd microseconds in half a second.\en",
+ (intmax_t) us);
exit(EXIT_SUCCESS);
}