重新初始化 timeval 结构 [英] Reinitialize timeval struct

查看:99
本文介绍了重新初始化 timeval 结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 time.h 重新初始化 timeval 结构?

How can I reinitialize a timeval struct from time.h?

我知道我可以将结构的两个成员都重置为零,但是我忽略了其他一些方法吗?

I recognize that I can reset both of the members of the struct to zero, but is there some other method I am overlooking?

推荐答案

对任意(可能是聚合)类型进行零初始化的完全正确且可移植(尽管是 C99)的方法:

The completely correct and portable (albeit C99) way to zero-initialize arbitrary (possibly aggregate) types:

myTime = (struct timeval){0};

这甚至适用于包含指针和浮点成员的结构,即使实现不使用全零位作为空指针和浮点零的表示.

This works even for structures that contain pointers and floating point members, even if the implementation does not use all-zero-bits as the representations for null pointers and floating point zeros.

这篇关于重新初始化 timeval 结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆