标签: g++

发布版本中是否禁用断言?

在'release'版本中是否禁用了断言?

如何可选的标志一样-O0,-O3,-gg++影响它的行为?

c++ linux assert g++

-3
推荐指数
1
解决办法
721
查看次数

int main = 0,已编译但崩溃

我有一个非常简单的程序,如下所示。

int main = 0;

此程序a.c与文件编译的罚款gcc-4.8gcc-5gcc-6gcc-7gcc-8和应用程序执行时坠毁。

a.cppg++-4.8和编译的文件相同的程序可以正常运行,g++-5并且应用程序在执行时崩溃。但是在更高版本的g ++中,它会给出编译时错误。

以下是我的问题。

  1. 为什么a.cpp使用g ++-4.8和5可以正常编译,而不能用更高版本编译?它是在旧版g ++中出错还是在c ++标准中有所改进?
  2. 如果编译成功,那么为什么应用程序崩溃?

下面是详细的编译器和编译/执行输出。

+ gcc-4.8 --version
gcc-4.8 (Ubuntu 4.8.5-4ubuntu8) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

+ gcc-4.8 c.c
+ ./a.out
Segmentation fault      (core dumped) …
Run Code Online (Sandbox Code Playgroud)

c c++ gcc g++

-3
推荐指数
1
解决办法
153
查看次数

如何在G ++中从.o文件创建exe/tar.bz2?

有没有办法在G ++中使用.o文件制作exe或tar.bz2 fiel?我必须使用nasm或任何其他程序来制作ax和tar.bz2,或者它可以在G ++中使用吗?

c++ compiler-construction exe g++ tar

-4
推荐指数
1
解决办法
419
查看次数

什么 - 我在g ++命令中暗示这里?

据我所知,在使用g ++编译时,-I用于包含头文件,并-L用于链接库文件.但这是一个位于以下行的google-breakpad minidump_file_writer_unittest的g ++编译命令33:

g++ -I../ ../common/convert_UTF.c \
 ../common/string_conversion.cc \
 minidump_file_writer.cc \
 minidump_file_writer_unittest.cc \
 -o minidump_file_writer_unittest
Run Code Online (Sandbox Code Playgroud)

现在究竟是什么意思-I../?是否包含此目录和子目录中的所有头文件?

c++ linux g++

-4
推荐指数
1
解决办法
86
查看次数

为什么我的c ++代码会进入无限循环?

我为LBM编写了一个C++代码来解决扩散方程,我在Ubuntu中用g ++编译它.编译得很好,但是当我尝试执行程序时,它并没有结束.我认为该程序有某种无限循环,但我无法解决在哪里?提前谢谢你们.

这是我的代码:

#include <iostream>
#include <fstream>

using namespace std;

int main(){
    const int Lx = 100;
    const int Ly = 100;
    int sMod = 8; //speed model 
    float f[sMod][Lx+1][Ly+1];
    float rho[Lx+1][Ly+1];
    float feq, sum;
    float x[Lx+1];
    float y[Ly+1];
    float csq, alpha, omega,Tw;
    float w[9] = {4./9., 1./9., 1./9., 1./9., 1./9., 1./36., 1./36., 1./36., 1./36.};
    int i, j, dt, dx, k, dy; 

    FILE * mFile;
    dt = 1.0;
    dx = 1.0;
    dy = dx;

    x[0] = 0.0;
    for(i = 1; …
Run Code Online (Sandbox Code Playgroud)

c++ g++ infinite-loop

-4
推荐指数
1
解决办法
128
查看次数

c中相同代码的不同答案

这段代码会发生什么?

#include <stdio.h>

int main(){
    int e;
    printf("%d ", e);
    printf("%s", e);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

e会有a)垃圾值吗?b)NULL

在GCC中它显示垃圾值,在g ++中它显示0和NULL.谢谢!!

c gcc g++

-4
推荐指数
2
解决办法
65
查看次数

为什么用g ++编译的代码比微软编译器更紧密?

我有以下代码,使用g ++运行3秒,在微软编译器运行超过30秒,我不明白...

struct constraint{
    int bitline;
    int result;
};  

// this vector is filled with about 1 milion items
vector<constraint> constraints;

for (int a = 0; a < constraints.size(); ++a)
{
    if (a% 100 == 0) cout << a << " "<<endl;
    for (int b = a; b < constraints.size(); ++b)
    {
        int anded = constraints[a].bitline & constraints[b].bitline;
        int ored =  constraints[a].bitline | constraints[b].bitline;

        // a subset of b
        if (anded == constraints[a].bitline && constraints[a].result >= constraints[b].result )
        {
            // …
Run Code Online (Sandbox Code Playgroud)

c++ g++ vector

-5
推荐指数
1
解决办法
202
查看次数

g ++抱怨STD功能

我有一段下载的源代码,当尝试使用g ++编译器通过Cygwin进行编译时,编译器给出了一个错误,指出'transform'函数在此范围内未声明...

我正在使用std命名空间,我有正确的标头.我不确定它为什么不编译..语法看起来正确

这是代码块部分.

string tolower (const string & s)
  {
    string d = s;
    transform(d.begin(), d.end(), d.begin(), (int(*)(int)) tolower);
    return d;
  }  // end of tolower
Run Code Online (Sandbox Code Playgroud)

这是我的标题部分:

#include <fcntl.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>

// standard library includes ...

#include <string>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stdexcept>
#include <fstream>
#include <iostream>
#include <sstream>
#include <ios>
#include <iterator>

using namespace std; 
Run Code Online (Sandbox Code Playgroud)

c++ g++ std

-5
推荐指数
1
解决办法
74
查看次数

-5
推荐指数
1
解决办法
66
查看次数

使用#define在C ++ / g ++中包含文件

我不想写:

#include MACRO(arg) 
Run Code Online (Sandbox Code Playgroud)

相反,我试图只写:

MACRO(arg)
Run Code Online (Sandbox Code Playgroud)

许多人说我们不能将这样的宏写到#include任何文件中,但是那些尝试仅在预处理阶段失败,在一个通过下面的预处理器之后失败,我想。

我编写了以下测试代码tmp1.cpp(无法编译):

#define HASH #
#define ZX(arg) HASH include <arg>

ZX(iostream)

int main()
{

}
Run Code Online (Sandbox Code Playgroud)

下面是一些命令的输出:

$ g++ -E tmp1.cpp
# 1 "tmp1.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "tmp1.cpp"



 # include <iostream>

int main()
{

}
$ g++ -E tmp1.cpp > tmp2.cpp
$ g++ tmp2.cpp
$ ./a.out
$ g++ tmp1.cpp
tmp1.cpp:1:14: error: stray ‘#’ in program
 #define HASH #
              ^
tmp1.cpp:2:17: note: …
Run Code Online (Sandbox Code Playgroud)

c++ g++

-5
推荐指数
1
解决办法
102
查看次数

标记“(”之前缺少二元运算符

错误:

cxx.cpp:5:13: error: missing binary operator before token "("
cxx.cpp:7:15: error: missing binary operator before token "("
Run Code Online (Sandbox Code Playgroud)

代码:

  #if definied(_WIN32) || definied(_WIN64) || definied(__WIN32__)
        const char * PORT = "COM1";
    #elif definied(__linux) || definied(__linux__) || definied(linux)
        const char * PORT = "dev/ttyS1";
    #else 
        const char * PORT = NULL;
    #endif
Run Code Online (Sandbox Code Playgroud)

问题:

  1. 编译器正在等待新的defined()调用?
  2. 它可以检测到任何 linux(和变体)或 windows 版本?

提前致谢。

c++ g++ preprocessor-directive

-7
推荐指数
1
解决办法
5810
查看次数

c ++,错误:命名空间'std'中的'shared_ptr'没有命名模板类型

我试图用rhapsody定义一个指向我结构的智能指针,我已经包含了头文件"memory".但我有上面的错误

 typedef std::shared_ptr<my_structure> %s;
Run Code Online (Sandbox Code Playgroud)

c++ boost g++ rhapsody

-7
推荐指数
1
解决办法
3804
查看次数

C++,数组中的地址

我对C++中的地址有一些有趣的问题.我有这样的代码:

#include <iostream>
#include <cstdlib>
using namespace std;

int main() {
    int N = 50 + rand() % 151;
    int arr[N];
    int arr2[N];
    int *ptr1;
    ptr1 = &arr[0];

    for(int i = 0; i < N; i++){
        cout << "Address1: "<< &arr[i]<< "\t" << "Address2: " << &arr2[i] << endl;
    }
}
Run Code Online (Sandbox Code Playgroud)

这段代码有效,但地址分配让我感到害怕.这样的输出合法吗?我认为它有点奇怪,第二个数组在内存中比第一个数组更早.如果有人知道是什么问题,请解释我有什么问题,因为根据定义顺序,首先必须是第一个数组的地址,而不是第二个地址.这是在Ubuntu中使用g ++编译的.

Address1: 0xbf9ab1b8    Address2: 0xbf9ab028
Address1: 0xbf9ab1bc    Address2: 0xbf9ab02c
Address1: 0xbf9ab1c0    Address2: 0xbf9ab030
Address1: 0xbf9ab1c4    Address2: 0xbf9ab034
Address1: 0xbf9ab1c8    Address2: 0xbf9ab038
Address1: 0xbf9ab1cc    Address2: 0xbf9ab03c
Address1: 0xbf9ab1d0    Address2: …
Run Code Online (Sandbox Code Playgroud)

c++ linux memory arrays g++

-10
推荐指数
1
解决办法
124
查看次数