public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "francois.hebert001 at videotron dot ca" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/107081] New: ctime fct used  twice in printf
Date: Thu, 29 Sep 2022 01:32:33 +0000	[thread overview]
Message-ID: <bug-107081-4@http.gcc.gnu.org/bugzilla/> (raw)

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 */

             reply	other threads:[~2022-09-29  1:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-29  1:32 francois.hebert001 at videotron dot ca [this message]
2022-09-29  1:39 ` [Bug c/107081] " pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-107081-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).