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