Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] It's time_t to Party!
- Date: Tue, 6 Dec 2005 13:41:11 -0500
- From: Jim <jep200404@example.com>
- Subject: Re: [tlug] It's time_t to Party!
- References: <20051202154627.GB4348@example.com> <20051202152527.302e2f6f.jep200404@example.com> <20051203122655.GG4348@example.com> <20051203092314.3118db01.jep200404@example.com> <20051204100726.GH4348@example.com> <30ce84360512040313l351f16c4r1872cb4f6f34679e@example.com> <20051206082734.GB4319@example.com>
Michal Hajek wrote: > printf("... %d.%09ld\n",> (int)ts.tv_sec, (long int)ts.tv_nsec); I'm focusing on the type of the .tv_sec element. On a box I use, it is a type_t type. Unfortunately, I don't know how to say: printf("%(type_t)d...",ts.tv_sec); which would be automatically be correct when type_t changes, or even better: printf("%(typeof ts.tv_sec)d...",ts.tv_sec); which would spare one from having to scrutinize the man pages (although one would still have to know that .tv_sec is an integral type), so one is stuck commiting to making a choice to use l or to not use l between % and d in the format string. On a box I use: .tv_sec is a type_t, which is a __type_t, which is a __TIME_T_TYPE, which is a __SLONGWORD_TYPE, which is a long int. Yuch! It was too hard to follow that chain of definitions with repeated grep -i foo /usr/include commands. There is such a hall of mirrors effect that one is not confident what the heck tv_sec is. I would figure the safer choice, would be to cast to a long (and use %ld) instead of a mere int. At worst, the cast to long slows down printf. At worst, the cast to int chops off significant bits. Granted, with 32-bit ints, that won't happen for about another 30 years, http://en.wikipedia.org/wiki/Unix_epoch#32-bit_overflow http://en.wikipedia.org/wiki/Year_2038_problem http://en.wikipedia.org/wiki/Unununium_Time#System_time and even then computers would likely have migrated to 64-bit ints time_t's which would make the issue moot, but that's what folks were saying about four-digit numbers for years in the (19)60s. (And what format is the data stored in?) It's like deja-vu all over again with Y2K. Some organizations already have to deal with this kind of issue, and just use their own format, like YYYY-MM-DD HH:MM:SS.sssssssssss... If it's for production code, I would first consider something that would avoid the need for any cast, then consider casting to a long. Casting to an int would be my last consideration. Of course, if your code is just a short term testing hack, then it doesn't matter. Of course, a completely different consideration would be to avoid using printf(), or the loosely typed C language. Some things are just best done in Emacs. http://en.wikipedia.org/wiki/Unix_epoch#time_t_parties Jim
- Follow-Ups:
- Re: [tlug] It's time_t to Party!
- From: Stephen J. Turnbull
- References:
- [tlug] timing for geeks :)
- From: Michal Hajek
- Re: [tlug] timing for geeks
- From: Jim
- Re: [tlug] timing for geeks
- From: Michal Hajek
- Re: [tlug] A Rich Experiment Indeed
- From: Jim
- Re: [tlug] A Rich Experiment Indeed
- From: Michal Hajek
- Re: [tlug] A Rich Experiment Indeed
- From: Ian Wells
- Re: [tlug] timing for geeks II.
- From: Michal Hajek
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] TLUG List Archives
- Next by Date: Re: [tlug] It's time_t to Party!
- Previous by thread: Re: [tlug] timing for geeks II.
- Next by thread: Re: [tlug] It's time_t to Party!
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links