-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests: Handle various time_t sizes in printf #124
Conversation
tests/kern/pathwalk.c
Outdated
msg ("Created %d objects in %"PRIdMAX".%.3"PRIdMAX"s", length * files + 1, | ||
(intmax_t)elapsed.tv_sec, (intmax_t)elapsed.tv_usec / 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
The format specifier macros are kind of clunky to use. Are they helpful here? In other projects we've just used %jd
for an intmax_t
argument. In a quick spot check of linux, freebsd, and macos, I'm seeing j
in all the printf(3) man pages.
Any reason not to go that way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just thought this was guaranteed to be portable. But as you say that might not be an issue for intmax_t
. I can change it if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't mind - please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed a new version using plain %jd
.
The members of the timeval struct are both signed (defined by POSIX) and typically both 64 bits on a system where time_t is 64 bits. This is possible also on 32 bit systems where time_t is larger to handle the 2038 problem. It's practically impossible to find a type and printf format that works even on all glibc systems. Play it safe and always use printf with intmax_t.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks!
This pull request has been removed from the queue for the following reason: The pull request can't be updated You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. If you want to requeue this pull request, you need to post a comment with the text: |
The members of the
timeval
struct are both signed (defined by POSIX) and typically both 64 bits on a system where ?time_t
is 64 bits. This is possible also on 32 bit systems wheretime_t
is larger to handle the 2038 problem.It's practically impossible to find a type and
printf
format that works even on all glibc systems. Play it safe and always useprintf
withintmax_t
.