这个问题涉及在Eclipse 4.2.2(Juno)中使用CDT 8.1.2管理的C++项目.以下代码片段将进行编译,但它将在Eclipse中显示为有错误.
我有一个名为foo.h的文件,内容如下:
int a = 42;
Run Code Online (Sandbox Code Playgroud)
该文件包含在另一个文件foo.cpp中:
#include <cstdio>
int main() {
#include "foo.h"
printf("%d", a);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如何修复"符号'无法解决"?根据我的理解,main()函数中的#include语句应该在预处理器中触发纯粹的复制粘贴操作.CDT似乎已正确索引文件,因为我可以按CTRL-单击文件名"foo.h",然后在IDE中打开文件.有趣的是,如果我在#include "foo.h"语句下面移动#include <cstdio>语句,它会按预期工作.CDT中是否有任何选项可以在解析符号之前执行预处理?
旁注:我知道这个代码设计是不受欢迎的,但我需要导入其他人编写的代码,并且需要正确设置内容辅助才能提高工作效率.
我是Haskell的初学者并用它来解决Project Euler的 50个问题,但现在我陷入问题66.问题是编译后的代码(ghc -O2 --make problem66.hs)在10-20秒后占用了我所有机器的空闲内存.我的代码看起来像这样:
-- Project Euler, problem 66
diophantine x y d = x^2 - d*y^2 == 1
minimalsolution d = take 1 [(x, y, d) | y <- [2..],
let x = round $ sqrt $ fromIntegral (d*y^2+1),
diophantine x y d]
issquare x = (round $ sqrt $ fromIntegral x)^2 == x
main = do
print (map minimalsolution (filter (not . issquare) [1..1000]))
Run Code Online (Sandbox Code Playgroud)
我有一种预感,问题在于列表理解中的无限列表minimalsolution.
我实际上认为,由于懒惰,Haskell只会评估列表,直到它找到一个元素(因为take 1)并且在路上丢弃 …
在 Go 中,由于类型不兼容,我遇到了编译错误,我无法解释。我正在使用该"C"模块。最小示例包含以下 2 个文件:
package module
import "C"
type T struct {
X C.int
}
Run Code Online (Sandbox Code Playgroud)
和一个主程序
package main
import (
"fmt"
"sandbox/module"
)
import "C"
func f() *module.T {
var x C.int = 42
return &module.T{X: x}
}
func main() {
fmt.Printf("value: %d", f().X)
}
Run Code Online (Sandbox Code Playgroud)
这无法编译并显示消息
./main.go:12: cannot use x (type C.int) as type module.C.int in field value。
由于某种原因,编译器认为C.int不等于module.C.int。
它一定与模块有关,C并且代码分布在两个模块中,因为如果我从C.intplain切换到它,它会突然起作用int。
为什么这段代码不能编译?使其编译而不将所有代码压缩在一个模块中的正确解决方案是什么?
我在 Ubuntu 16.04 上使用最新的 Go …