1
在z/OS上,pthread_t
类型是一个包含成员char __[8];
的结构。我试图将其从返回值转换为int64_t
。我得到了以下错误:为什么xlC++编译器抱怨转换右值?
CCN5216 (S) An expression of type "char [8]" cannot be converted to type "int64_t"
但是,如果使用一个临时变量tmp
它的工作原理。我可以使用Visual Studio 2015编译此代码(定义类似于zos pthread_t
的自定义mypthread
结构),而不会出错。你知道为什么xlC++在演员阵容方面有问题吗?演员标准是否符合?
#define _OPEN_THREADS
#include <iostream>
#include <stdint.h>
#include <pthread.h>
pthread_t apr_os_thread_current() {
return pthread_t();
}
int64_t getId() {
pthread_t tmp = apr_os_thread_current();
return (int64_t) tmp.__; // ok
//return (int64_t) apr_os_thread_current().__; // CCN5216
//return reinterpret_cast<int64_t>(apr_os_thread_current().__); // CCN5216
}
int main() {
std::cout << getId() << std::endl;
return 0;
}
是的,你是对的:输出为“哎呀! 515113908“ –
This works:'return *((int64_t *)&apr_os_thread_current().__ [0]);' –
为什么要将不透明结构转换为int64_t? z/OS pthread_t实际上是两个整数,一个序列号和一个指向线程控制块(TCB-任务控制块)的指针。我过去做过的唯一原因是在日志中打印TCB。 –