在'release'版本中是否禁用了断言?
如何可选的标志一样-O0,-O3,-g的g++影响它的行为?
我有一个非常简单的程序,如下所示。
int main = 0;
此程序a.c与文件编译的罚款gcc-4.8,gcc-5,gcc-6,gcc-7和gcc-8和应用程序执行时坠毁。
与a.cpp用g++-4.8和编译的文件相同的程序可以正常运行,g++-5并且应用程序在执行时崩溃。但是在更高版本的g ++中,它会给出编译时错误。
以下是我的问题。
下面是详细的编译器和编译/执行输出。
+ 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) 有没有办法在G ++中使用.o文件制作exe或tar.bz2 fiel?我必须使用nasm或任何其他程序来制作ax和tar.bz2,或者它可以在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../?是否包含此目录和子目录中的所有头文件?
我为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) 这段代码会发生什么?
#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.谢谢!!
我有以下代码,使用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) 我有一段下载的源代码,当尝试使用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) http://coliru.stacked-crooked.com/a/252266963e43652a
与
http://coliru.stacked-crooked.com/a/838b3b45b25f577e
为什么我说:
[&, data]() mutable {} vs. [&data]() mutable {}
Run Code Online (Sandbox Code Playgroud)
应该是?或者不应该?
(有变化的功能是append_data()).
我不想写:
#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) 错误:
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)
问题:
defined()调用?提前致谢。
我试图用rhapsody定义一个指向我结构的智能指针,我已经包含了头文件"memory".但我有上面的错误
typedef std::shared_ptr<my_structure> %s;
Run Code Online (Sandbox Code Playgroud) 我对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)