问题标签 [g++4.8]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
1400 浏览

c++ - tan() 计算比使用 g++ 4.8.2 的 sin()/cos() 长两倍

我正在处理使用大量数学函数的算法,最近我们在 Solaris 平台的 Ubuntu 系统上移植了 g++ 4.8.2 下的代码。

令人惊讶的是,一些算法比以前花费了很多时间。背后的原因是std::tan()函数比做的时间长两倍std::sin()/std::cos()

用 sin/cos 代替 tan 大大减少了相同结果的计算时间。我想知道为什么会有这样的差异。是因为标准库的实现吗?tan 函数不应该更有效吗?

我写了一个程序来检查函数的时间:

事实上,在输出中我有以下没有优化的时间:

并通过优化 (-O2) :

如果有人对此行为有任何想法。

编辑

我根据@Basile Starynkevitch 的回复修改了程序:

现在结果我-O2只得到了类似的时间:

但仍然有区别-O2 -mtune=native,但确实更快:

我不会使用-ffast-math,因为我需要保持 IEEE 合规性。

0 投票
2 回答
5042 浏览

c++ - 不一致的警告:变量可能被“longjmp”或“vfork”破坏

我基本上确信我遇到了一些 g++ 4.8.3 的错误,但我想我会先问这个列表,因为我对 setjmp/longjmp 的经验很少。我已将有问题的代码简化为以下 foo.cxx:

我使用 g++ 4.8.3 来编译这段代码。令我感兴趣的是,当我定义 USE_STRUCT 时,编译失败但使用 USE_INT 成功。代码中有注释进一步说明了如何使用 USE_STRUCT 使编译成功。g++ 的 -fPIC 选项也只会导致编译失败,但这是我的环境中的必需参数。

查看编译错误:

但是使用简单的 int 就可以了:

有人可以向我解释为什么 val 如果它是一个结构而可能会被破坏,但如果它是一个 int 则不会?如代码中的注释所示,有关使结构成功编译的其他方法的任何见解?或者这是否指向编译器错误?

非常感谢任何见解和评论。

0 投票
3 回答
3880 浏览

matlab - using C++11 in Mex with g++ 4.8 in linux

I'm trying to call a function I wrote in C++ 11 from a mex script. The C++ code requires -std=c++11, and runs fine from the terminal. Here's g++ -v output: gcc version 4.8.2 20140120 (Red Hat 4.8.2-15) (GCC) I have Matlab 2013a for Red Hat.

When I first tried calling mex filename.cpp from matlab console I got:

This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

So, I went into the /usr/local/MATLAB/R2013a/bin/mexopts.sh file that matlab uses to get compler options and added -std=c++11. Now I get:

cc1plus: error: unrecognized command line option "-std=c++11"

The full command gotten from mex -v filename.cpp is:

So, how can I get this to compile properly?

0 投票
3 回答
9846 浏览

c++ - 空向量的大小

以下程序在g++ 4.8.232 位 Linux 系统上运行时给出了输出 12:

我看到了这一点,并且知道这sizeof(v)可能是特定于实现的。不过,我想知道是什么可能导致该向量的大小为 12。我认为迭代器v.begin()可能v.end()会导致 8 个字节的大小。我对么?如果是,是什么导致了剩余 4 个字节的大小?如果不是,那么这 12 个字节到底是什么?

0 投票
1 回答
430 浏览

c++ - 返回 std::string 时指针无效(libc 这么说)

我在 mmapped 文件消费类中有一个成员函数,如下所示:

('OFFSET' 的类型是 unsigned long long)

其存在的理由是 (a) 返回假定存在于 offset 处的空终止 C 字符串的 std::string *offsetp,在 (b) 推进*offsetp超过所述 C 字符串末尾的值之后。

我在很多情况下都调用这个函数,没有问题。然而,我最近添加了一个新的调用,它总是以一种特殊的方式 SIGABRT:

上面的消息后面是一个回溯(最终是 libc.so.6 中的一些代码)和一个内存映射......这两者在调试这个问题时表面上对我来说都是有用的。

通过使用 GDB 进行调试,我了解到 SIGABRT 实际上并没有发生在我Data::GetASCIIZ上面引用的方法中,而是发生在在赋值右侧调用它的代码中。(所以,我假设在调用 std::string 的复制构造函数期间):

[编辑:更新为与@WhozCraig 的预期答案相吻合]

在这种特殊情况下,偏移处的 C 字符串恰好是一个空字符串,但我已经通过临时修改以指向 GDB 中的其他内容来*offsetp验证这不是必然的。*offsetp

我的方法被标记是const因为它不会修改Data对象的任何内部状态。我正在返回一个存在于堆栈上的对象,但我不是通过引用这样做的,并且我希望复制构造函数(在调用代码中)在该堆栈项被破坏之前做正确的事情。

我尝试重写该GetASCIIZ方法以使用显式本地,但这没有帮助。

我错过了什么吗?

如果它有用,这里是这个 SIGABRT 发生的 call-during-assignment 的反汇编。('==>' 是错误的地方。)

0 投票
1 回答
404 浏览

c++ - 与实际内存内容相比,GDB 内存检查输出减少了 8 个字节

在将几 KB 的内存转储到复杂的 C++ 对象时,我从 GDB 的x命令获得的内存转储输出之间出现了奇怪的不一致。在 GDB 提示符下,我得到:

这对应于对象成员的异常值,例如值不是 0 或 1 的布尔值。但是,当从 /proc/ pid /mem 转储此内存区域的内容时,我在前 8 个字节中得到 0,然后是相同的内存内容如上(左栏为十进制内存偏移量):

我在 Linux 3.13(Ubuntu 14.04)上使用 GDB 7.7.1。我的代码是 C++ 11,我使用系统附带的 g++ 4.8.2 进行编译。

我用来转储上面显示的 /proc/.../mem 内容的 Python 脚本:

任何帮助将不胜感激!

0 投票
2 回答
4207 浏览

c++ - 递增一个 const 指针

我有这段代码..

为什么当我尝试为指针指向的常量整数分配一个新值时它会显示错误,但当我尝试增加值时却没有。
当我增加*rptr它时,它为它分配了一个未定义的值,所以我试图检查两者是否都指向同一个地址并且它们确实如此。

这是前面代码的输出,但没有包含错误的行:

在 Linux x86 机器上使用 g++4.8

0 投票
1 回答
378 浏览

c++11 - 用于 C++11 的编译器 g++

我通过 macport 安装了 g++ 4.8。我可以通过调用 g++-mp-4.8 来使用它。

我用 g++ 4.8 编译这段代码,看看我是否得到了 C++11,但答案是预标准 C++。这怎么可能?注意:我希望 C++11 可以使用自动迭代器。

0 投票
1 回答
264 浏览

c++ - 元组作为返回类型,是否优化了未访问的值?

我以std::tuple.

由于必须使用std::getor访问返回值std::tie,编译器是否针对未使用的值进行了优化(g++ 4.8)?

0 投票
0 回答
164 浏览

c++ - Issue in building 32 bit application in 64 Bit build environment

Build Environment:

  1. 64 Bit Ubuntu 14.04

Supporting Libraries:

  1. OpenCV

I am able to generate 64 bit .so's in 64 bit Ubuntu environment.[Using GCC with OpenCV Built in 64 bit.] There is not problem in it.

I hope, if i want to build to 32 bit in 64 bit environment, i need to set -m32 flag and more importantly pointing or referring 32 bit supporting packages(OpenCV) Am i right here?

Steps i done:

  1. Removed the 64 bit opencv library folder from the /usr/local of my 64 bit machine

  2. Then,Copy and paste the Pre-build opencv library of 32 bit in /usr/local of my 64 bit machine

Created the sample opencv code and executed the following commands:

I have doubt in my steps ,whether i done the correct steps or not.

I am getting error. Please provide the answer if any one have tried.