我有一个C程序试图修改const字符串文字.就像现在我了解到这是不允许的.
当我用clang test.c编译器编译代码时没有给出警告.但是当我用clang++ test.c它编译它时会发出警告:
test.c:6:15:警告:不推荐将字符串文字转换为'char*'[-Wdeprecated-writable-strings] char*s ="hello world"; ^
问题是它结果clang++只是一个符号链接clang:
ll `which clang++`
lrwxr-xr-x 1 root admin 5 Jan 1 12:34 /usr/bin/clang++@ -> clang
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,如果它是符号链接,那么它的clang++行为会有clang什么不同clang?
如果是这样,我该如何开启?我自己在文档中找不到这个,谷歌没有提供有用的结果
例如,
int arr[2];
arr[5] = n; // runtime error
Run Code Online (Sandbox Code Playgroud) 考虑这个代码示例:
#include <initializer_list>
#include <iostream>
int main()
{
for(auto e: []()->std::initializer_list<int>{return{1,2,3};}())
std::cout<<e<<std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我尝试用g ++编译它(gcc版本4.9.2(Debian 4.9.2-10)),输出正确.在clang ++中(Debian clang版本3.5.0-9(标签/ RELEASE_350/final)(基于LLVM 3.5.0))输出例如:
0
2125673120
32546
Run Code Online (Sandbox Code Playgroud)
第一行总是0,最后两行是"随机".
这是clang或其他什么的错误?我认为这个代码示例是正确的.
更新:
当lambda函数返回类型是别的东西(例如std :: vector或std :: array)时,这段代码工作正常.
我正在尝试将Google的Address Sanitizer与CUDA项目结合使用,更准确地说是使用OpenCV cuda功能.但是我在第一次cuda电话上遇到了"内存不足"的错误.
OpenCV Error: Gpu API call (out of memory) in getDevice, file opencv-2.4.11/src/opencv-2.4.11/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp, line 664
terminate called after throwing an instance of 'cv::Exception'
what(): opencv-2.4.11/src/opencv-2.4.11/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp:664: error: (-217) out of memory in function getDevice
Run Code Online (Sandbox Code Playgroud)
它可以复制
#include <opencv2/gpu/gpu.hpp>
int main()
{
cv::gpu::printCudaDeviceInfo(cv::gpu::getDevice());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
用.编译
clang++ -fsanitize=address -lstdc++ -lopencv_gpu -lopencv_core -o sanitizer sanitizer.cpp && LD_LIBRARY_PATH=/usr/local/lib ./sanitizer
Run Code Online (Sandbox Code Playgroud)
我用gcc得到了同样的结果.我也尝试过将cuda函数列入黑名单而没有结果.
现在使用没有opencv的cuda:
#include <cuda_runtime.h>
int main()
{
int count = -1;
cudaGetDevice(&count);
cout << "Device count: " << count << endl; …Run Code Online (Sandbox Code Playgroud) #include <iostream>
void f() { std::cout << "f()\n"; }
struct S {
typedef void(*p)();
operator p() { return f; }
};
int main()
{
S s;
s.operator p()();
}
Run Code Online (Sandbox Code Playgroud)
产量:
Run Code Online (Sandbox Code Playgroud)main.cpp:13:16: error: unknown type name 'p'; did you mean 'S::p'? s.operator p()(); ^ S::p main.cpp:6:19: note: 'S::p' declared here typedef void(*p)(); ^
但它应该,因为表达式s.operator p()()访问对象的公共成员函数S::s.我错过了什么吗?
如果我错了,我会很感激标准中引用的答案.
两个编译器为此代码示例生成不同的结果.Clang生成两种不同的类型.G ++使用相同的类型fu和fi.哪一个符合标准?
#include <iostream>
template< auto IVAL>
struct foo {
decltype(IVAL) x = -IVAL;
};
int main()
{
foo<10u> fu;
foo<10> fi;
std::cout << fi.x << " " << fu.x << '\n';
return 0;
}
Run Code Online (Sandbox Code Playgroud)
g ++ - 7.3输出:
4294967286 4294967286
clang-6.0输出:
-10 4294967286
亲爱的Assembly/C++ dev,
问题是:传播两个ASM块之间的进位(或任何标志)是现实的还是完全疯狂的,即使它有效?
几年前,我为低于512位的大型算术开发了一个整数库(在编译时).我此时没有使用GMP,因为对于这种规模,GMP由于内存分配而变慢,并且模型选择二进制表示工作台.
我必须承认我创建了我的ASM(字符串块)使用BOOST_PP,它不是非常光荣(好奇的看看它vli).图书馆运作良好.
但是我注意到,此时不可能在两个ASM内联块之间传播状态寄存器的进位标志.这是合乎逻辑的,因为对于编译器在两个块之间生成的任何助记符,寄存器被复位(mov指令除外(来自我的汇编知识)).
昨天我有一个想法,传播两个ASM块之间的进位有点棘手(使用递归算法).它工作,但我认为我很幸运.
#include <iostream>
#include <array>
#include <cassert>
#include <algorithm>
//forward declaration
template<std::size_t NumBits>
struct integer;
//helper using object function, partial specialization is forbiden on functions
template <std::size_t NumBits, std::size_t W, bool K = W == integer<NumBits>::numwords>
struct helper {
static inline void add(integer<NumBits> &a, const integer<NumBits> &b){
helper<NumBits, integer<NumBits>::numwords>::add(a,b);
}
};
// first addition (call first)
template<std::size_t NumBits, std::size_t W>
struct helper<NumBits, W, 1> {
static …Run Code Online (Sandbox Code Playgroud) 我编写了以下简单的 C++ 程序:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World" << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我用 g++ 编译它时,它工作得很好。当我尝试使用 Clang++ 进行编译时,出现以下错误:
main.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
Run Code Online (Sandbox Code Playgroud)
使用-v参数运行,我看到以下内容:
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/backward"
ignoring nonexistent directory "/include"
ignoring duplicate directory "/usr/include/clang/6.0.0/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++
/usr/include/clang/6.0.0/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
Run Code Online (Sandbox Code Playgroud)
分别查看这些文件夹,我发现在/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++(或更简洁地说,在/usr/include/c++ …
我刚刚将我的MacBook Pro更新到macOS Catalina 10.15,并尝试编译和运行C++ 命令行程序,但我遇到了以前版本不存在的问题;
这是简单的代码:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!\n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
代码编译并输出预期,但 Xcode 仍然说:
fatal error: 'iostream' file not found
Run Code Online (Sandbox Code Playgroud)
我尝试将Build Settings/C++ Standard Library更改为libstdc++,但警告说:
warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead
Run Code Online (Sandbox Code Playgroud)
并且仍然存在相同的 iostream 错误。