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

* [Bug c/107081] ctime fct used  twice in printf
  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 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-09-29  1:39 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
ctime returns the same pointer no matter what. It 


https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf

The ctime function returns the pointer returned by the asctime function with
that
broken-down time as argument.

"Execution of
any of the functions that return a pointer to one of these object types may
overwrite the
information in any object of the same type pointed to by the value returned
from any
previous call to any of them and the functions are not required to avoid data
races.
"

^ 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).