简体   繁体   English

从time_t到const time_t的无效转换*

[英]invalid conversion from time_t to const time_t*

time_t raw_time = time(NULL);
tm* current_time = localtime(&raw_time);

I got the answer myself... I totally messed up the warnings. 我自己得到了答案...我完全弄错了警告。 Thanks anyway. 不管怎么说,还是要谢谢你。

The localtime() function dates back to when (int) was 16 bits and passing (long) on the stack was not widely supported; localtime()函数的历史可以追溯到(int)为16位并且在堆栈上传递(long)不受广泛支持。 as such, it was specified to pass (long *) , which at the time was 16 bits. 因此,它指定通过(long *) ,当时为16位。 It's been left as is because changing it would break enormous amounts of code. 之所以保留它是因为更改它会破坏大量的代码。 You'll find that most of the time-related functions do this, since they were the only functions at the time that used (long) . 您会发现大多数与时间相关的函数都可以执行此操作,因为它们是当时使用的唯一函数(long) ( lseek() came later. Care to guess what non- (long) -using function it replaced?) lseek()稍后问世。要猜猜它替换了哪些非(long)使用函数?)

localtime requires an argument of "time_t*" which is a pointer. localtime需要参数“ time_t *”,它是一个指针。 So you have to put the & there. 因此,您必须将&放在那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM