我使用的是gcc 4.9.0,我希望看到编译器警告我超出了数组界限。如果我编译这段代码
int main()
{
int table[5]={0};
table[8] = 1234;
int x = table[10];
}
使用g++ -O2 -Wall main.cpp -o main.exe时,我只收到有关未使用的x的警告:
main.cpp: In function 'int main()':
main.cpp:8:7: warning: unused variable 'x' [-Wunused-variable]
int x
根据我的记忆,下面这段代码应该可以在C++上很好地编译,但不能在C中编译,唯一的问题是如何测试它?它在g++上编译得很好,在gcc上也是如此。我假设g++是C++编译器,而gcc是C编译器。我已经在Windows下用mingw尝试过了。我说的对吗?如果不是,那么如何使用C编译器编译它。
int main() {
const int i = 1;
const int j = 2;
const int k = 3;
int array[i + j + k];
return 0;
}
代码:
struct A
{
private:
A() = default; // Version 1.
};
struct B : public A
{};
struct C
{
private:
C() {}; // Version 2.
};
struct D : public C
{};
int main()
{
B b; // Compiles under g++ 4.7.2
D d; // Compilation error under g++ 4.7.2
}
还有两种情况( gcc 4.7.2):
如果我编
在以下代码中,变量定义B<int, int>(14);应该是错误的:
#include <iostream>
struct A {
};
template<class T, class R=A>
class B {
public:
explicit B(const int s, R n = A()) {
std::cout << "c\n";
}
};
template <class T, class R=A>
void foo(const int s, R nx = A())
我正在尝试从make文件编译几个C++文件。我一直在犯这个错误:
<i> no member named 'to_time_t' in
'std::__1::chrono::steady_clock'; did you mean
'std::chrono::system_clock::to_time_t'?
time_t tnow = std::chrono::high_resolution_clock::to_time_t(now);
</i>
经过一些研究后,我发现这是因为我没有使用
我想在之后安装MK-Livestatus来连接nagios和thruk。
当我尝试使用./configure && make进行编译时,它会提示我:
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make s
查看问题并尝试一些代码:
int x = 100;
while ( 0 <-------------------- x )
{
printf("%d ", x);
}
我尝试用gcc编译,得到以下错误:
file.c: In function 'main':
file:c:10:27: error: lvalue required as decrement operand
while ( 0 <-------------------- x )
但是使用g++进行编译是可行的。为什么这段代码在C++中有效,而在C中无效?
下面这个简单的程序不能在cygwin中用gcc编译
#include <string>
#include <iostream>
int main()
{
std::cout << std::to_string(4) << std::endl;
return 0;
}
命令行:
$ g++ -std=c++0x to_string.cc
错误:
to_string.cc: In function ‘int main()’:
to_string.cc:6:16: error: ‘to_string’ is not a member of ‘
当我与gcc一起编译以下代码时:
int main()
{
unsigned char c = 1;
c <<= 1; // WARNING ON THIS LINE
return 0;
}
我收到警告:
conversion to ‘unsigned char’ from ‘int’ may alter its value [-Wconversion]
为什么?这段代码有什么问题?实际上,我真的可以在一个<<=变量上使用操作器unsigned char吗?
编译命令:
g++ test.cpp -Wconversion -o test.exe
我正在使用一个工具链,它似乎包装了gcc (qcc),但也使用了g++来做一些事情。当我不能使用g(q)cc链接我用g++构建的库时,这引起了一些混淆,尽管它是针对相同的体系结构的(由于缺少库错误)。经过更多的研究,我发现g++基本上就是具有一些默认标志和一个稍微不同的文件扩展名解释机制的gcc (可能还有其他不同之处我已经浏览过了)。我想确切地知道哪些标志可以传递给gcc,以便等同于g++调用。例如:
g++ -g -c hello.cpp // I know at the very least that this links in stl
gcc -g -c -??? /