g++

No compiler warning for returning a reference to local variable

走远了吗. 提交于 2019-12-24 04:17:34
问题 Using: g++ -Wall -ansi foo.cpp I get the warning foo.cpp:31: warning: reference to local variable ‘x’ returned from the function : int &bar(int x) { return x; } but, removing that function from the file, I get no warning from the following function: int &get_max(int x, int y) { return x > y ? x : y; } Why does the compiler allow this? 回答1: It looks like a bug, the warning is inconsistent, if we turn on optimization in gcc 5.1 it does catch this case: warning: function may return address of

Use gcc plugins to modify the order of variable declarations

家住魔仙堡 提交于 2019-12-24 03:23:26
问题 I know this is very hard to do, and that I should avoid that, but I have my reasons for this. I want to modify the order of some field declarations in compilation time, for example : class A { char c; int i; } must turn to : class A { int i; char c; } if I chose to swap the order of i and c , I want to know how to change the location of a field declaration having its tree Anyone know how can I do this ?? thanks ! I use the g++ 4.9.2 version of plugins 回答1: If I was going to try this, I would

Use gcc plugins to modify the order of variable declarations

烂漫一生 提交于 2019-12-24 03:23:19
问题 I know this is very hard to do, and that I should avoid that, but I have my reasons for this. I want to modify the order of some field declarations in compilation time, for example : class A { char c; int i; } must turn to : class A { int i; char c; } if I chose to swap the order of i and c , I want to know how to change the location of a field declaration having its tree Anyone know how can I do this ?? thanks ! I use the g++ 4.9.2 version of plugins 回答1: If I was going to try this, I would

Static linking with boost python

我的梦境 提交于 2019-12-24 03:19:57
问题 I'm trying to create a boost python extension but would prefer to statically link the boost python libraries. Otherwise you need the exact same version of boost installed on every machine you use the python module. I'm not using bjam though. This works in linux (ubuntu) but results in dynamic linking: g++ -o python_example.o -c python_example.cpp -Wall -fPIC -I/usr/include/python2.7 g++ -shared -o python_example.so python_example.o -lpython2.7 -lboost_python -lboost_system python_example.cpp

G++ compiler: Segfault handling

╄→гoц情女王★ 提交于 2019-12-24 02:43:23
问题 I'm working on a project where I call a function which triggers a segfault. I fixed this, but during the process I noticed the following. When my code is of the format; main(){ ... std::cout << "Looking for segfault\n"; // this does not print buggyFunction(); // crashes in here ... } buggyFunction(){ ... thing_that_causes_segfault; ... } The line "Looking for segfault" doesn't print to STD, and the program crashes in buggyFunction. Fine, but when I add a cout line inside buggyFunction(); main

Eclipse CDT error: Unable to compile

老子叫甜甜 提交于 2019-12-24 02:24:11
问题 I tried to run a simple Hello world program. I am getting this error when I try to build it. What does it mean and how do I resolve it? I am using Windows 7 and I have MinGW and MSys in the %PATH%. **** Build of configuration Debug for project learn **** **** Internal Builder is used for build **** g++ -IC:\MinGW\lib\gcc\mingw32\4.5.2\include\c++ -IC:\MinGW\libexec\gcc\mingw32\4.5.2 -O0 -g3 -Wall -c -fmessage-length=0 -osrc\learn.o ..\src\learn.cpp g++: CreateProcess: No such file or

Access maximum template depth at compile?

拈花ヽ惹草 提交于 2019-12-24 01:49:09
问题 In a certain compilation I need to play around with the option -ftemplate-depth=N that specifies the maximum template recursion. Is it possible to access the value of the maximum template depth from the program? I am interested in gcc or clang . $ c++ -ftemplate-depth=128 main.cpp #include<iostream> int main(){ std::cout << MAX_TEMPLATE_RECURSION << std::endl; // hypothetical name } 来源: https://stackoverflow.com/questions/36227436/access-maximum-template-depth-at-compile

Resolving undefined references with MySQL C++ Connector

浪子不回头ぞ 提交于 2019-12-24 00:52:41
问题 I'm trying to compile this (also listed in the mysql c++ connector documentation): http://pastebin.com/HLv4zR0r But I get these errors: http://pastebin.com/3t0UbeFy This is how I tried compiling: g++ -o test test.cpp `mysql_config --cflags --libs` -I./include/cppconn -L./lib -lmysqlcppconn-static The result of running mysql_config --cflags --libs is: -I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing -g -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -ldl Edit: After

Pipe file contents in g++ to compile

社会主义新天地 提交于 2019-12-23 23:38:33
问题 Is it possible to pipe the contents of a file into g++ to compile a program? I want to do this because I want to use a file from a database rather than a physical file on a disk. The file contents can be easily retrieved via an API I have made. For instance, I would like to do something like: g++ contents_of_file -o executable Thanks a lot. Sam. 回答1: Yes, you can pipe to gcc if you specify the language using the -x option; echo "int main(){}" | gcc -Wall -o testbinary -xc++ - 回答2: more fun:

oprofile unable to produce call graph

百般思念 提交于 2019-12-23 23:15:10
问题 I am trying to use oprofile to generate call graph. Compiler is g++, platform is linux x86-64, linker is gfortran C++ code is compiled with -fno- omit-frame-pointer. oprofile is started with --callgraph=25. report I run with --callgraph. the call graph is produced but it's only includes self time, which is not much use what am I missing? 回答1: Check if opcontrol --status does not have Call-graph depth: 0 in its output. If it does, stop profiling, do opcontrol --callgraph=<desired call stack