c++ - 巨大的 initializer_list 编译段错误

标签 c++ qt gcc

    const QHash<QString, float> idfs = {{"the", 0.0023450551861261},
    {"of", 0.00258603321106053},
    {"to", 0.00375511856396871},
    {"and", 0.0040408455383457}

..293060行更多

编译命令:/usr/local/bin/mpic++ -DQT_CORE_LIB -DQT_NO_DEBUG --isystem/usr/include/x86_64-linux-gnu/qt5 -isystem/usr/include/x86_64-linux-gnu/qt5/QtCore -isystem/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -Wall -Wextra -std=c++11 -O2 -fPIC -fPIC -o CMakeFiles/antiplagiarism.dir/src/idfs.cc.o -c/home/user/newanalyzer/common/src/idfs.cc

编译结果:g++: internal compiler error: Segmentation fault (program cc1plus)

gcc 有一个巨大的初始化列表可以吗?

gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 

最佳答案

Is it ok to have huge initialization list for gcc?

是的。让它太大以至于您构建的系统耗尽资源是不好的。 gcc 的体系结构没有固有的限制。

但这是静态数据,QHash 是错误的工具。你应该使用类似 gperf 的东西而是使用用户提供的结构。

在您的情况下,gperf 的输入文件如下所示:

 %language=C++
 %struct-type
 %define class-name WordHash
 %define slot-name text
 struct Word { const char *text; double frequency; };
 %%
 the, 0.0023450551861261
 of, 0.00258603321106053
 to, 0.00375511856396871
 and, 0.0040408455383457

使用 gperf 生成的代码,您将按如下方式查找:

double getFrequency(const char *text) {
  auto *word = WordHash::in_word_set(text, strlen(text));
  Q_ASSERT(!word || strcmp(word->text, text) == 0);
  return word ? word->frequency : -1;
}

关于c++ - 巨大的 initializer_list 编译段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50758747/

相关文章:

c++ - 打印整数指针 vector 的值

c++ - qt 5.2串口写问题与windows 7

c++ - 无符号字符数组的十六进制 QString 表示

c - 查找 off_t 大小

c++ - 如何让虚拟析构函数在 C++ 中被调用?

C++ 帮助解决编译器错误

c++ - Boost 程序选项 - 获取部分中的所有条目

c++ - UI::MainWindow 找不到成员

c - 'printf'原理

gcc - 使用 GCC(内联汇编程序)将双倍加载到 FPU