最近,当我为Fortran程序员编写C简介时,其中一位Fortran程序员向我询问了类型转换.对他而言,在C语言中你必须显式地转换变量而不是让编译器自动为你做这件事并没有多大意义.
我实际上有点难以说明这是好事,因为它有助于避免无意的错误.
你怎么称义这个?
所以我试图在我的opencl主机代码中初始化一个变量,如下所示:
cl_float2 es = (cl_float2)(0.0f,0.0f);
Run Code Online (Sandbox Code Playgroud)
哪个,使用Clang 2.9,失败了:
source/solveEikonalEq.c:75:38: warning: expression result unused [-Wunused-value]
cl_float2 es = (cl_float2)(0.0f,0.0f);
^~~~
source/solveEikonalEq.c:75:26: error: cast to union type from type 'float' not present in union
cl_float2 es = (cl_float2)(0.0f,0.0f); //ray's tangent vector
^ ~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)
并且,在使用GCC 4.6.1时,失败的原因是:
source/solveEikonalEq.c:75:42: warning: left-hand operand of comma expression has no effect [-Wunused-value]
source/solveEikonalEq.c:75:26: error: cast to union type from type not present in union
Run Code Online (Sandbox Code Playgroud)
我正在使用AMD的opencl sdk,并且可以很好地构建示例.我做错了什么?
考虑C中的以下typedef结构:
21:typedef struct source{
22: double ds; //ray step
23: double rx,zx; //source coords
24: double rbox1, rbox2; //the box that limits the range of the rays
25: double freqx; //source frequency
26: int64_t nThetas; //number of launching angles
27: double theta1, thetaN; //first and last launching angle
28:}source_t;
Run Code Online (Sandbox Code Playgroud)
我得到错误:
globals.h:21:错误:重新定义'struct
source'globals.h:28:错误:'source_t'globals.h的冲突类型
:28:注意:'source_t'的先前声明在这里
我尝试过使用其他格式来定义:
struct source{
...
};
typedef struct source source_t;
Run Code Online (Sandbox Code Playgroud)
和
typedef struct{
...
}source_t;
Run Code Online (Sandbox Code Playgroud)
哪两个都返回相同的错误.为什么会这样?它看起来非常适合我.
所以我已经交了一个python项目,其中有很多Linux系统调用mount/unmout/format/etc备份驱动器用于定制的NAS.
现在我想处理umount命令的输出并处理已卸载路径的情况:
print subprocess.check_output(['umount', '/storage/backup'])
Run Code Online (Sandbox Code Playgroud)
可能会返回:
umount: /storage/backup: not mounted
Command '['umount', '/storage/backup']' returned non-zero exit status 32
Run Code Online (Sandbox Code Playgroud)
现在,我可以解析输出字符串并搜索not mounted,但我更喜欢处理退出状态值(在本例中为32).我试图找到umount命令的退出代码列表,但到目前为止还不走运.
此外,我已经尝试找到umount的源代码,但一直无法找到它(谷歌一直指向umount命令的手册页或源代码mount.c)
编辑
手册页umount有错误列表(非数字),如:
然后: 下面给出的错误值来自文件系统类型独立错误.每种文件系统类型都可能有自己的特殊错误和自己的特殊行为.有关详细信息,请参阅Linux内核源代码.
有什么指针吗?