ctime and time warnings compiling on OSX

北慕城南 提交于 2020-01-06 05:28:04

问题


I am getting some warnings when compiling a C program on OSX 10.6.5, which seem to be quite critical.

extras.c:15: warning: implicit declaration of function ‘time’
extras.c: In function ‘outlog’:
extras.c:363: warning: implicit declaration of function ‘ctime’

The corresponding lines are as follows:

Lines 13-15:

RANDNUMGEN = gsl_rng_alloc(gsl_rng_taus);
long t1;
(void) time(&t1);

Lines 360-363:

if (LOG==NULL) { LOG=stdout;}

TVAL = time(NULL);
char* TIMESTRING = ctime(&TVAL);

I believe the program was originally written for Linux, so I wonder if there is a difference between time and ctime on the two platforms?


回答1:


Verify that the C files contains:

#include <time.h>

somewhere around the top.

Also,

long t1;
time(t1);

is pretty lousy code, the argument to time() has type time_t*, so that should read

time_t t1;
time(&t1);


来源:https://stackoverflow.com/questions/5041374/ctime-and-time-warnings-compiling-on-osx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!