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

B

baumann@pan

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.
 
N

Nelu

baumann@pan said:
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.
 
B

baumann@pan

"Nelu дµÀ£º
"
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...


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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top