PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > gcc printf conversion specification for struct timeval
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
gcc printf conversion specification for struct timeval

Réponse
 
LinkBack Outils de la discussion
Vieux 29/11/2007, 09h43   #1
PawelCarqowski
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 29/11/2007, 10h04   #2
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: gcc printf conversion specification for struct timeval

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.

  Réponse avec citation
Vieux 29/11/2007, 10h31   #3
Ian Collins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: gcc printf conversion specification for struct timeval

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.
  Réponse avec citation
Vieux 29/11/2007, 10h43   #4
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: gcc printf conversion specification for struct timeval

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.

  Réponse avec citation
Vieux 29/11/2007, 11h17   #5
Duncan Muirhead
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: gcc printf conversion specification for struct timeval

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
  Réponse avec citation
Vieux 29/11/2007, 12h21   #6
Spoon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: gcc printf conversion specification for struct timeval

santosh wrote:

> struct timeval is a GNU C extension.


http://opengroup.org/onlinepubs/0096...ys/time.h.html

The <sys/time.h> header 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. for GCC-specific questions.
  Réponse avec citation
Vieux 29/11/2007, 12h22   #7
Spoon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: gcc printf conversion specification for struct timeval

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? :-)
  Réponse avec citation
Vieux 29/11/2007, 13h00   #8
James Kuyper
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: gcc printf conversion specification for struct timeval

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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 23h09.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11981 seconds with 16 queries