我在Ubuntu 9.04 64位上使用GCC 4.3.3,并且在C代码中使用C++风格的注释会出错.当我在标题中说"默认"时,我的意思是简单地调用gcc test.c
根据GCC 4.3.3文档(这里),这是支持的...但我仍然得到了错误.
这些错误随着我的编译字符串添加了一个简单的-std = c99而消失了,所以我的问题就解决了.很奇怪,如果有任何GCC专家对此有解释,因为在我看来,这与文档明显矛盾.
#include <stdio.h>
// this is a comment
int main( void )
{
return 0;
}
Run Code Online (Sandbox Code Playgroud) 这是一段代码:
class Class
{
static constexpr int getBug();
};
constexpr int Class::getBug()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我基本上做的是static constepxr在类声明中声明一个方法,然后我实现它.
原始代码分为两个文件,并包含更多已剥离的方法/属性,只留下所需的代码.
当我编译代码时,我从GCC 4.6.0得到以下错误:
Class.cpp:6:29: internal compiler error: in merge_types, at cp/typeck.c:825
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Run Code Online (Sandbox Code Playgroud)
这真的是个bug吗?
在那种情况下,我必须提供什么报告?
我已经在在线C++ 0x编译器上测试了代码并得到以下错误:
prog.cpp:3:33: error: the 'constexpr' specifier cannot be used in a function declaration that is not a definition
prog.cpp:6:29: error: a constexpr function cannot be defined outside of its …Run Code Online (Sandbox Code Playgroud) 我正在使用gcc 4.6.2.
我正在尝试在向量shared_ptr中推送back_back.
但gcc每次都给我一个错误.
这是我的代码行:
std::vector< std::tr1::shared_ptr<Process> > procs;
std::string line;
while (getline(file, line) && line.find(JobMask) != std::string::npos)
{
std::string procName = line.substr(line.find(JobMask) + JobMask.size());
std::vector<Instruction> procInstructions = extractProgram(file);
std::queue<int> procInputs = extractInputs(file);
if (!procInstructions.empty())
procs.push_back(std::make_shared<Process>(Process(procName, procInputs, procInstructions))); //line 51
}
return procs;
Run Code Online (Sandbox Code Playgroud)
我的gcc给出的错误是:
Process.cpp: In static member function 'static std::vector<std::tr1::shared_ptr<RMMIX::Process> > RMMIX::Process::createProcesses(const string&)':
Process.cpp:51:95: error: no matching function for call to 'std::vector<std::tr1::shared_ptr<RMMIX::Process> >::push_back(std::shared_ptr<RMMIX::Process>)'
Process.cpp:51:95: note: candidates are:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/include/g++-v4/bits/stl_vector.h:826:7: note: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::tr1::shared_ptr<RMMIX::Process>, _Alloc = …Run Code Online (Sandbox Code Playgroud) 我有以下简单的代码行:
#include <glib.h>
#include <stdio.h>
void my_func () {
GHashTable htbls[3]; /* ASSUME LINE NUMBER IS N */
/* Do something */
}
int main (int argc, char *argv[]) {
my_func ();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但
$gcc `pkg-config --cflags --libs glib-2.0` ./main.c
Run Code Online (Sandbox Code Playgroud)
给出以下错误:
./main.c:N: error: array type has incomplete element type
Run Code Online (Sandbox Code Playgroud)
我不明白为什么元素类型不完整. GHashTable是完全指定的glib.h.
在此先感谢您的帮助.
可能重复:
在"模板化基类"中调用模板方法时出错
以下代码使用MSVC10进行编译,但不使用gcc 4.2.1进行编译:
template<class BaseQNativeWindow>
class NativeWindow : public BaseQNativeWindow
{
public:
NativeWindow(AIPanelPlatformWindow handle) : BaseQNativeWindow(handle)
{}
protected:
virtual void closeEvent(QCloseEvent *e)
{
QList<QWidget *> childrenList;
childrenList = BaseQNativeWindow::findChildren< QWidget * >(); // GCC ERROR
foreach(QWidget *child, childrenList)
{
child->close();
}
}
};
Run Code Online (Sandbox Code Playgroud)
这就是gcc抱怨的:
error: expected primary-expression before ‘*’ token
error: expected primary-expression before ‘>’ token
error: expected primary-expression before ‘)’ token
Run Code Online (Sandbox Code Playgroud)
findChildren是一种BaseQNativeWindow必须提供的模板化方法.似乎gcc假设findChildren在知道什么类型之前不是模板BaseQNativeWiindow.有谁能解释一下?
谢谢.
将原始类型的typedef改为另一种原始类型是有效的C++吗?
typedef int long;
Run Code Online (Sandbox Code Playgroud)
在VS 2012上,发出警告但编译正常.
警告C4091:'typedef':当没有声明变量时,在'long'的左边忽略
但是在gcc-4.3.4上,它失败了.
错误:声明不声明任何内容.
哪个编译器符合标准?
PS:我不会在生产代码中写这样的东西.刚想出想法和检查.
使用GCC6和下面的代码片段,这个测试
if (i > 31 || i < 0) {
Run Code Online (Sandbox Code Playgroud)
是false,执行此printf
printf("i > 31 || i < 0 is FALSE, where i=%d", i);
Run Code Online (Sandbox Code Playgroud)
并产生这个非常奇怪的输出(GCC6):
我> 31 || i <0为FALSE,其中i = 32/*奇怪的结果与GCC6!*/
而对于GCC4,我得到:
我> 31 || i <0为真,其中i = 32/*结果Ok GCC4*/
看起来很不错.
怎么会这样??
static int check_params(... input parameters ...) {
/* Note that value can be 0 (zero) */
uint32_t value = ....
int i;
i = __builtin_ctz(value);
if (i …Run Code Online (Sandbox Code Playgroud) pow不接受第二个参数作为gcc的变量
以下代码适用于VC++ 10
// file test.cc
#include "stdafx.h"
#include <stdio.h>
#include <math.h>
int main(void)
{
double x = 10;
int y = 20;
printf("%f\n", pow(x, y));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是以下代码对gcc不起作用:
// test.c
#include <stdio.h>
#include <math.h>
int main(void)
{
double x = 10;
int y = 20;
printf("%f\n", pow(x, y)); // error here, says no such function, however when pass the second argument in `pow` for the code runs by gcc, It works fine!
return 0;
}
Run Code Online (Sandbox Code Playgroud) 任何人都可以帮助我理解使用gcc编译时-ffast-math选项的作用.使用-O3和-ffast-math执行时,我看到程序执行时间相差20秒,而只使用-O3