473,405 Members | 2,300 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,405 software developers and data experts.

why could I not write static time_t current_time = time(); in c program?

Hi,

i write
static time_t current_time = time();

but the gcc compiler complains:
error: initializer element is not constant.

I want to know
1, why,
2, and how to resovle it.

thanks.

Jan 22 '07 #1
2 3273
baumann@pan <ba*********@gmail.comwrote:
Hi,

i write
static time_t current_time = time();
The time function should be called with a pointer to a time_t object or
NULL:
time_t time(time_t *tloc);

Fix that first...
>
but the gcc compiler complains:
error: initializer element is not constant.

I want to know
1, why,
2, and how to resovle it.

thanks.
.... then (n1124.pdf) 6.7.8-4: "All the expressions in an initializer for an
object that has static storage duration shall be constant expressions or
string literal."

In your case it's a function call.
--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)

Jan 22 '07 #2

"Nelu дµÀ£º
"
baumann@pan <ba*********@gmail.comwrote:
Hi,

i write
static time_t current_time = time();

The time function should be called with a pointer to a time_t object or
NULL:
time_t time(time_t *tloc);

Fix that first...

but the gcc compiler complains:
error: initializer element is not constant.

I want to know
1, why,
2, and how to resovle it.

thanks.

... then (n1124.pdf) 6.7.8-4: "All the expressions in an initializer for an
object that has static storage duration shall be constant expressions or
string literal."
thank you!!!!
In your case it's a function call.
--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
Jan 22 '07 #3

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

Similar topics

2
by: Suresh | last post by:
hello, i am new to c and how do i use time function to get time. thanks, Sean
1
by: Tomas Deman | last post by:
Hi all, I have a problem converting a borland cpp (v4.52) time_t value to a visual basic date. What does borland exactly store? I heard this should be #seconds since 1/1/1970 0:00 in EST time....
0
by: Zwyatt | last post by:
I have the following code (simplified here): #include <time.h> class A { public: char *aString; int aNum; time_t aTime; }
0
by: Zwyatt | last post by:
having a really weird little bug w/ time_t...check it out: I have the following code (simplified here): #include <time.h> class A { public: char *aString; int aNum;
2
by: Joseph Turian | last post by:
When does initialization of static member variables occur? In the following code fragment, is m_start_time automatically initialized right before main()? Or is m_start_time uninitialized...
8
by: Henrik Goldman | last post by:
I have strings like "2006-03-26 21.51" which I would like to convert into time_t. I know that the string is in localtime. So far I've written the following code: time_t...
1
by: Alan Johnson | last post by:
Consider the following class template, which has the static member 'seed_'. This template is intended to be inherited by several other classes using the curiously recurring template pattern, so...
7
by: Yuanfei | last post by:
Hi There, I just found that there is a problem in vc2005 regarding to time_t and localtime. See code snippets belows. Using this code segment, I found that when ut is 86200, the corresponding...
45
by: loudking | last post by:
Hello, all I don't quite understand what does ((time_t)-1) mean when I execute "man 2 time" RETURN VALUE On success, the value of time in seconds since the Epoch is retu rned. On error,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.