472,796 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,796 software developers and data experts.

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 18766
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tim Quon | last post by:
Hi I have a function which needs a struct timeVal as timeout parameter. How can I initialize this struct to a timeout of 3 seconds? Thanks Tim
3
by: buzzdee | last post by:
hi, i just wanted to print out some unsigned long int values in hexadecimal, printing out one value works, but not byte by byte. anybody has a suggestinon what my problem is? this is my...
12
by: John Devereux | last post by:
Hi, I would like to know if their is a conversion specifier, or other method, that will allow me to not use particular arguments to printf. Failing that, is it permissable to simply "not use"...
8
by: Tony Houghton | last post by:
I'm writing a python program which reads input device events so it needs to know sizeof(struct timeval). By using the struct module I should be able to work out sizeof(long) from python, but I...
43
by: Joe Smith | last post by:
#include <stdio.h> int main(void) { unsigned long gcd(unsigned long m, unsigned long n); unsigned long m; unsigned long n; unsigned long t; m = 2520; n = 154;
11
by: timmu | last post by:
Someone asked me a question about integer division and printf yesterday, I tell him he should do a casting to float/double before you do any interger division. But he doesn't think so, so I try...
2
by: sapsi | last post by:
Hi, I am using a library (pcapy) that returns a timeval object T= (seconds,microseconds) where microseconds is always < 1e6. Is there a Python class that can handle timeval structs? Specifically,...
5
by: Joe | last post by:
I'm trying to add the current time + a randomly generated time w/ millisecond precision, but the numbers aren't making sense. If I add rand_time + now_time on my calculator, I get a different...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.