- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望将 timeval 字段附加到我的自定义数据包 header 中。面临类型转换的问题。
标题中我的自定义字段
struct pkthdr {
uint64_t sec;
uint64_t usec;
}
Linux timeval 结构体
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* and microseconds */
}
初始化
struct pkthdr *hdr;
struct timeval *tm;
gettimeofday(&tm, 0);
hdr->sec = htonl(tm->tv_sec);
hdr->usec = htonl(tm->tv_usec);
以下行导致段错误
hdr->sec = htonl(tm->tv_sec);
hdr->usec = htonl(tm->tv_usec);
最佳答案
您已经创建了指向 struct timeval
和 struct pkthdr
的指针,但实际上尚未分配任何要指向的内存,因此当您尝试执行以下操作时,您正在调用未定义的行为为 hdr->sec
和 hdr->usec
您还向 gettimeofday
传递了错误的类型,因为您传递的是 struct timeval **
而不是 struct timeval
。
尝试创建实际的结构而不是指向它们的指针:
struct pkthdr hdr;
struct timeval tm;
gettimeofday(&tm, NULL);
hdr.sec = htonl(tm.tv_sec);
hdr.usec = htonl(tm.tv_usec);
检查以确保 hdr.sec
和 hdr.usec
中的数据确实是您想要的,因为这可能不正确。我对使用 htonl
有一些保留,因为它处理 32 位数据,而您的预期结果是 64 位。
关于c - timeval 到 uint64_t 网络位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56992597/
根据在线文档,这些固定宽度整数类型之间存在差异。对于 int*_t,我们将宽度固定为 * 的值。然而对于其他两种类型,描述中使用形容词最快和最小来请求底层数据模型提供的最快或最小实例。 “最快”或“最
我是 Python 注释的新手(类型提示)。我注意到 pyi 中的许多类定义文件继承到 Generic[_T] , 和 _T = TypeVar('_T') . 我很困惑,_T 是什么意思?这里的意思
这个问题在这里已经有了答案: How to use a variable inside a _T wrapper? (3 个答案) 关闭 7 年前。 我有以下代码: CString port = m
要包含 _T() 宏,我应该包含什么文件?它转换我认为的文本文字。我以为它是 windows.h,但我已经包含了它。 令人惊讶的是,我无法在 Google 上找到答案。 最佳答案 我在主题 Unico
类型的后缀 _t 由 POSIX 保留,但是如果我在自己的命名空间中使用 _t 后缀定义自己的类型怎么办? 最佳答案 我同意 user6366161 的 answer,其中说“C 对 namespac
我知道 size_t 有 _t 后缀,因为它的别名/typedef。但是我不明白为什么 char16_t, char32_t 和 wchar_t 包含 _t 后缀。 最佳答案 对于 wchar_t :
我想让这个字符串的主机名部分可变..目前,它只修复了这个 URL: _T(" --url=http://www.myurl.com/ --out=c:\\current.png"); 我想做这样的东西
这个问题在这里已经有了答案: convert string to _T in cpp (6 个答案) 关闭 7 年前。 string pagexx = "http://website.com/" +
我有一个注册为 COM 对象的 .net 库,当在 C++ 项目中导入 .tlb 文件时,我得到这样的方法声明 virtual HRESULT __stdcall GetBid ( /*[
我现在遇到了很多 Unicode 问题。据我了解,TCHAR 被定义为 wchar_t 或 char,具体取决于 _UNICODE 是否在某处定义,并且还有各种其他功能可以帮助解决这个问题。显然 _T
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 9 年前。 Improve t
我正在尝试使用 _t() 方法翻译一个 DataObject。 我一直在 Pages 上使用它没有问题,但它似乎不适用于数据对象。 class SliderItem extends DataObjec
关于保留 _t 结尾名称的规则是否也适用于作用域名称(例如,在 namespace 或类中定义的类型和类型定义),还是仅适用于全局 namespace 中的类型和类型定义?标准 C/C++ 库或 PO
我确定以前有人问过这个问题,但我无法搜索到文本。如果有人可以解释它们,请给我推荐一篇文章,或者给我正确的搜索查询,我将不胜感激。 谢谢。 最佳答案 这只是一种预感,但看看 Wikipedia C++1
我有一个 UNICODE 应用程序,我们使用 _T(x) 定义如下。 #if defined(_UNICODE) #define _T(x) L ##x #else #define _T(x) x #
我一直想知道是否存在任何命名约定,例如何时对类型使用 ALLCAPS 以及何时附加 _t(以及何时不使用任何东西?)。我知道以前 K&R 发布了各种关于如何使用 C 的文档,但我找不到任何相关内容。
这似乎是一个简单的问题,但我无法通过 Stack Overflow 搜索或 Google 找到它。类型后跟 _t 是什么意思?比如 int_t anInt; 我在 C 代码中经常看到它与硬件密切相关—
C++ 有时使用后缀 _type关于类型定义(例如 std::vector::value_type ),有时_t (例如 std::size_t ),或者没有后缀(普通类,还有像 std::strin
字符串中的“T”代表什么。例如 _T("Hello")。我在需要 unicode 支持的项目中看到了这一点。它实际上告诉处理器什么 最佳答案 _T 代表“文本”。当且仅当您使用 Unicode 支持编
我的代码可以根据 C++ 类型识别您需要使用的 GL 类型。我想制作它的 _t 版本(如 std::decay_t 或 std::enable_if_t)但公开 int常量值 template st
我是一名优秀的程序员,十分优秀!