468,463 Members | 2,022 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,463 developers. It's quick & easy.

gcc printf conversion specification for struct timeval

Hallo group members,
Do You know any conversion specification for this. I imagine:

struct timeval time;
printf("%T\n", time);

regards,
Pawel
Nov 29 '07 #1
7 17958
PawelCarqowski wrote:
Hallo group members,
Do You know any conversion specification for this. I imagine:

struct timeval time;
printf("%T\n", time);
struct timeval is a GNU C extension. There are no specific format
specifiers for this but since the structure members are of type long
int you can use the 'ld' format specifier for printing them.

For furher GNU C related questions please ask in a GNU group or in a
Linux group.

Nov 29 '07 #2
santosh wrote:
PawelCarqowski wrote:
>Hallo group members,
Do You know any conversion specification for this. I imagine:

struct timeval time;
printf("%T\n", time);

struct timeval is a GNU C extension.
It's POSIX.

--
Ian Collins.
Nov 29 '07 #3
Ian Collins wrote:
santosh wrote:
>PawelCarqowski wrote:
>>Hallo group members,
Do You know any conversion specification for this. I imagine:

struct timeval time;
printf("%T\n", time);

struct timeval is a GNU C extension.

It's POSIX.
You're right, thanks.

Nov 29 '07 #4
On Thu, 29 Nov 2007 10:43:25 +0100, PawelCarqowski wrote:
Hallo group members,
Do You know any conversion specification for this. I imagine:

struct timeval time;
printf("%T\n", time);

regards,
Pawel
I use
printf( "%ld.%.6ld\n", time.tv_sec, time.tv_usec);
which produces output like
1194509197.415800
Nov 29 '07 #5
santosh wrote:
struct timeval is a GNU C extension.
http://opengroup.org/onlinepubs/0096...ys/time.h.html

The <sys/time.hheader shall define the timeval structure that
includes at least the following members:

time_t tv_sec Seconds.
suseconds_t tv_usec Microseconds.

The time_t and suseconds_t types shall be defined as described
in <sys/types.h>.

time_t and clock_t shall be integer or real-floating types.

The type suseconds_t shall be a signed integer type capable of
storing values at least in the range [-1, 1000000].
There are no specific format specifiers for this [...]
Right.

(However, glibc does allow custom conversion specifiers.)

http://www.gnu.org/software/libc/man...ng-Printf.html
but since the structure members are of type long int
you can use the 'ld' format specifier for printing them.
AFAIU, it is possible for time_t to be wider than long int, but
I'm not sure. Consider a platform where time_t is 64 bits wide
and long int is only 32 bits wide.
For furher GNU C related questions please ask in a GNU group
or in a Linux group.
comp.unix.programmer for Unix-related questions.
gnu.gcc.help for GCC-specific questions.
Nov 29 '07 #6
Duncan Muirhead wrote:
PawelCarqowski wrote:
>Do You know any conversion specification for this. I imagine:

struct timeval time;
printf("%T\n", time);

I use
printf( "%ld.%.6ld\n", time.tv_sec, time.tv_usec);
which produces output like
1194509197.415800
What does it print when tv_usec = 666? :-)
Nov 29 '07 #7
Spoon wrote:
....
AFAIU, it is possible for time_t to be wider than long int, but
I'm not sure. Consider a platform where time_t is 64 bits wide
and long int is only 32 bits wide.
time_t can be any arithmetic type. It could even be _Imaginary; which
has some interesting :-) implications.
Nov 29 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Tim Quon | last post: by
3 posts views Thread by buzzdee | last post: by
12 posts views Thread by John Devereux | last post: by
8 posts views Thread by Tony Houghton | last post: by
43 posts views Thread by Joe Smith | last post: by
11 posts views Thread by timmu | last post: by
2 posts views Thread by sapsi | last post: by
5 posts views Thread by Joe | last post: by
reply views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.