public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/107081] New: ctime fct used  twice in printf
@ 2022-09-29  1:32 francois.hebert001 at videotron dot ca
  2022-09-29  1:39 ` [Bug c/107081] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: francois.hebert001 at videotron dot ca @ 2022-09-29  1:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107081

            Bug ID: 107081
           Summary: ctime fct used  twice in printf
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: francois.hebert001 at videotron dot ca
  Target Milestone: ---

If I use twice the ctime fct in the same printf, only the first value is print
twice.
If I use two printf both val;ue are printed correctly :
...
time_t now,now_beg,now_fin;
...
 printf("Beginning time ->%s Finishing time>%s\n",ctime(&now_beg),  
    ctime(&now_fin));
  printf("Beginning time->%s\n",ctime(&now_beg));
  printf("Finishing time->%s\n",ctime(&now_fin));

The result  is :

Sep 28 20:37:17 2022

Beginning time ->Wed Sep 28 20:37:15 2022
 Finishing time->Wed Sep 28 20:37:15 2022 <- should be not 20:37:15 but
20:37:17

Beginning time->Wed Sep 28 20:37:15 2022

Finishing time->Wed Sep 28 20:37:17 2022


Here is the Linux and gcc versions and the complete source used
/*

                gcc -o test_ctime test_ctime.c
               ./test_ctime
Fedora 36 astronomy 5.17.5-300
gcc --version
gcc (GCC) 12.0.1 20220413 (Red Hat 12.0.1-0)
Copyright © 2022 Free Software Foundation, Inc.

*/

#include <stdio.h>
#include <limits.h>
#include <time.h>



long cpt;
long j,limit;
time_t now,now_beg,now_fin;

/*******************************************************************************************

                          Main section

*******************************************************************************************/
int main()
{
  cpt=0;
  j=0;
  /*limite=LONG_MAX;*/
  limit=900000000;

  printf("Limit->%d\n",limit);
  time(&now_beg);
  printf("Begining time -> %s\n",ctime(&now_beg));
  for  (cpt=0;cpt<limit;cpt++)
  {
    if (cpt % 100000000 == 0)
     {
       time(&now);
       printf("%u   now->%s\n",cpt,ctime(&now));
     }
  }
  time(&now_fin);

  printf("Beginning time ->%s Finishing time->%s\n", 
     ctime(&now_beg),ctime(&now_fin));
  printf("Beginning time->%s\n",ctime(&now_beg));
  printf("Finishing time->%s\n",ctime(&now_fin));

  return 0;

}  /* end main section */

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-29  1:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-29  1:32 [Bug c/107081] New: ctime fct used twice in printf francois.hebert001 at videotron dot ca
2022-09-29  1:39 ` [Bug c/107081] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).