我有一个简单的代码,根据它是用.c还是.cu扩展名保存,编译方式不同:
[DataContract]
public class NewRequestTO
{
[DataMember]
public string guid { get; set; }
[DataMember]
public string title { get; set; }
[DataMember]
public string description { get; set; }
[DataMember]
public string category { get; set; }
[DataMember]
public string email { get; set; }
[DataMember]
public string priority { get; set; }
[DataMember]
public string type { get; set; }
[DataMember]
public string typeText { get; set; }
[DataMember]
public string categoryText { get; set; }
[DataMember]
public string subCategoryText { get; set; }
[DataMember]
public string files { get; set; }
}
如果我使用#include <stdio.h>
#include <complex.h>
int main()
{
float num;
float eps_i, eps_s, tau_d, sigma;
float pi, wave_freq, eps_0;
eps_i = 43.0;
eps_s = 2.4;
tau_d = 0.3;
sigma = 4.75;
pi = 3.14;
wave_freq = 0.015;
eps_0 = 40.234;
float complex c1 = 0.0 + 2.0 * pi * wave_freq * tau_d * I;
float complex c2 = 0.0 + sigma / (2.0 * pi * wave_freq * eps_0) * I;
num = creal(eps_i + (eps_s - eps_i) / (1.0 + (0.0 + 2.0 * pi * wave_freq * tau_d * I)) -
(0.0 + sigma / (2.0 * pi * wave_freq * eps_0) * I));
printf("%g\n", num);
}
编译它,它的确如此符合我的预期。但是,如果我运行nvcc test.c
,我会得到:
nvcc test.cu
我知道.cu被视为包含CUDA代码的代码而.c只是主机代码,但我希望它们在这个实例中的行为相同。请注意,它根本不会抱怨test.cu(18): error: expected a ";"
test.cu(19): error: "complex" has already been declared in the current scope
test.cu(19): error: expected a ";"
test.cu(21): error: identifier "I" is undefined
test.cu(21): error: identifier "creal" is undefined
test.cu(18): warning: variable "complex" was declared but never referenced
test.cu(19): warning: variable "complex" was declared but never referenced
5 errors detected in the compilation of "/var/folders/3z/8bl4b3yx0c3_5tgf35dr_z180000gp/T//tmpxft_00015a75_00000000-9_test.cpp1.ii".
。我错过了什么?