473,396 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with time() using g++

Hi all,
I have come across very strange behavior of the return value of the
time() function. Below is the program to illustrate the problem: The
value of NOW somehow changes after the call to the ifstream
constructor.

#include <iostream>
#include <fstream>
#include <time.h>

int main(int argc, char** argv)
{
if (argc != 2)
{
std::cout << "Usage: ctest filename" << std::endl;
exit(-1);
}
time_t NOW = time(0);
std::cout << "Start time before the call to ifstream(): NOW="
<< NOW << std::endl;
std::ifstream infile(argv[1]);
std::cout << "Start time after the call to ifstream(): NOW="
<< NOW << std::endl;
infile.close();
exit(0);
}

I tried this program with g++ 3.1.1 compiler on Solaris 5.8 and here
is the output:
g++ -o test test.cxx
test test.cxx Time before the call to ifstream(): NOW=1083075439
Time after the call to ifstream(): NOW=27503
Given the signature of the time() (time_t time(time_t* t)) I was not
able to find any reasonable explanation how the call to the ifstream
constructor could affect the local variable it does not know about so
any help would be greatly appreciated.

By the way, I tried the same program with CC Sun Workshop 6.2 and it
works fine. CC -o test test.cxx
test test.cxx Time before the call to ifstream(): NOW=1083075848
Time after the call to ifstream(): NOW=1083075848

---
Thanks,
Mike Alexeev
Jul 22 '05 #1
3 2553
"Mike Alexeev" <mi*************@qwest.com> wrote in message
news:85**************************@posting.google.c om...
Hi all,
I have come across very strange behavior of the return value of the
time() function. Below is the program to illustrate the problem: The
value of NOW somehow changes after the call to the ifstream
constructor.

#include <iostream>
#include <fstream>
#include <time.h>

int main(int argc, char** argv)
{
if (argc != 2)
{
std::cout << "Usage: ctest filename" << std::endl;
exit(-1);
}
time_t NOW = time(0);
std::cout << "Start time before the call to ifstream(): NOW="
<< NOW << std::endl;
std::ifstream infile(argv[1]);
std::cout << "Start time after the call to ifstream(): NOW="
<< NOW << std::endl;
infile.close();
exit(0);
}

I tried this program with g++ 3.1.1 compiler on Solaris 5.8 and here
is the output:
g++ -o test test.cxx
test test.cxx Time before the call to ifstream(): NOW=1083075439
Time after the call to ifstream(): NOW=27503


Given the signature of the time() (time_t time(time_t* t)) I was not
able to find any reasonable explanation how the call to the ifstream
constructor could affect the local variable it does not know about

so any help would be greatly appreciated.

By the way, I tried the same program with CC Sun Workshop 6.2 and it
works fine.
CC -o test test.cxx
test test.cxx

Time before the call to ifstream(): NOW=1083075848
Time after the call to ifstream(): NOW=1083075848


Works fine with gcc 3.2 on W2K.
Time to reinstall!
--
Gary
Jul 22 '05 #2
Mike Alexeev wrote:
Hi all,
I have come across very strange behavior of the return value of the
time() function. Below is the program to illustrate the problem: The
value of NOW somehow changes after the call to the ifstream
constructor.

#include <iostream>
#include <fstream>
#include <time.h>

int main(int argc, char** argv)
{
if (argc != 2)
{
std::cout << "Usage: ctest filename" << std::endl;
exit(-1);
}
time_t NOW = time(0);
std::cout << "Start time before the call to ifstream(): NOW="
<< NOW << std::endl;
std::ifstream infile(argv[1]);
std::cout << "Start time after the call to ifstream(): NOW="
<< NOW << std::endl;
infile.close();
exit(0);
}

I tried this program with g++ 3.1.1 compiler on Solaris 5.8 and here
is the output:

g++ -o test test.cxx
test test.cxx


Time before the call to ifstream(): NOW=1083075439
Time after the call to ifstream(): NOW=27503
Given the signature of the time() (time_t time(time_t* t)) I was not
able to find any reasonable explanation how the call to the ifstream
constructor could affect the local variable it does not know about so
any help would be greatly appreciated.

By the way, I tried the same program with CC Sun Workshop 6.2 and it
works fine.
CC -o test test.cxx
test test.cxx


Time before the call to ifstream(): NOW=1083075848
Time after the call to ifstream(): NOW=1083075848


Try putting this after your #include's:

#undef NOW

Alternatively, don't use all-caps identifiers for anything but macros.
Jul 22 '05 #3
Jeff Schwab <je******@comcast.net> wrote in message news:<g9********************@comcast.com>...
Mike Alexeev wrote:
Hi all,
I have come across very strange behavior of the return value of the
time() function. Below is the program to illustrate the problem: The
value of NOW somehow changes after the call to the ifstream
constructor.

#include <iostream>
#include <fstream>
#include <time.h>

int main(int argc, char** argv)
{
if (argc != 2)
{
std::cout << "Usage: ctest filename" << std::endl;
exit(-1);
}
time_t NOW = time(0);
std::cout << "Start time before the call to ifstream(): NOW="
<< NOW << std::endl;
std::ifstream infile(argv[1]);
std::cout << "Start time after the call to ifstream(): NOW="
<< NOW << std::endl;
infile.close();
exit(0);
}

I tried this program with g++ 3.1.1 compiler on Solaris 5.8 and here
is the output:

g++ -o test test.cxx
test test.cxx


Time before the call to ifstream(): NOW=1083075439
Time after the call to ifstream(): NOW=27503
Given the signature of the time() (time_t time(time_t* t)) I was not
able to find any reasonable explanation how the call to the ifstream
constructor could affect the local variable it does not know about so
any help would be greatly appreciated.

By the way, I tried the same program with CC Sun Workshop 6.2 and it
works fine.
CC -o test test.cxx
test test.cxx


Time before the call to ifstream(): NOW=1083075848
Time after the call to ifstream(): NOW=1083075848


Try putting this after your #include's:

#undef NOW

Alternatively, don't use all-caps identifiers for anything but macros.


The name does not matter. I tried it with different ones with the same result.
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
4
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a...
4
by: Gactimus | last post by:
Hey again, I am working my way through the book "C++ Primer Fourth Edition". I am trying to run a program out of the book using Microsoft Visual C++ version 6 and I am given the error message:...
5
by: towers | last post by:
Hello, I've got a bit of experience in C++, but I'm writing my first app that is dependent on relatively precise math functions. The app requires that I get a time stamp based on s sample...
11
by: Geoff Jones | last post by:
Hi I have a table that has a column with Date types. I am trying to view certain rows in the table using a DataView. Using the filter, I can view the rows with, for example, the date equal...
20
by: Development - multi.art.studio | last post by:
Hello everyone, i just upgraded my old postgres-database from version 7.1 to 7.4.2. i dumped out my 7.1 database (with pg_dump from 7.1) as an sql-file with copy-commands and to one file using...
0
by: Magnus Lundberg | last post by:
Hi, I'm trying to create a XML document looking like this: <?xml version="1.0" encoding="UTF-8"?> <rss> <Header> <FromDate>2006-10-01</FromDate> <ToDate>2007-06-01</ToDate>
3
by: Franky | last post by:
Been having a problem using a treeview. Work great the first time the form containing it is entered but not the second time. Took a while to create a small sample that exhibits the problem, but...
9
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
1
by: sherifbk | last post by:
Problem description ============== - I have 4 clients and 1 server (SQL server) - 3 clients are Monitoring console 1 client is operation console - Monitoring console collects some data from...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.