g++

Why does GCC optimization not work with valarrays?

空扰寡人 提交于 2019-12-12 07:47:14
问题 This is a simple c++ program using valarrays: #include <iostream> #include <valarray> int main() { using ratios_t = std::valarray<float>; ratios_t a{0.5, 1, 2}; const auto& res ( ratios_t::value_type(256) / a ); for(const auto& r : ratios_t{res}) std::cout << r << " " << std::endl; return 0; } If I compile and run it like this: g++ -O0 main.cpp && ./a.out The output is as expected: 512 256 128 However, if I compile and run it like this: g++ -O3 main.cpp && ./a.out The output is: 0 0 0 Same

Abstract Syntax Tree representation in C++

£可爱£侵袭症+ 提交于 2019-12-12 07:09:32
问题 I already have the tokenizer interface which creates a list of tokens. I have the working mechanism for the parser. It's really unique and works like a charm. The only thing that i miss is the basic structure of the AST. How the tree, the nodes and the statements should be represented on abstraction level. I don't need any implementation only a quick idea how should it look like in class hierarchy? I'm working on an object-oriented language. Yeah, i already realized that i will need two types

How to speed up g++ compile time (when using a lot of templates)

心不动则不痛 提交于 2019-12-12 07:07:59
问题 This question is perhaps somehow odd, but how can I speed up g++ compile time? My C++ code heavily uses boost and templates. I already moved as much as possible out of the headers files and use the -j option, but still it takes quite a while to compile (and link). Are there any tools out there which analyse my code and point out bottle-necks for the compiler? Or can one somehow profile the compiler running on my code? This would be really nice, because sometimes I have the impression, that I

method chain a derived class method after calling a base class method

这一生的挚爱 提交于 2019-12-12 06:38:31
问题 With a class and a derivative as shown below, is there a way for the base classes methods to return a object reference of the derived type instead of its own type so syntactically i can chain the methods together? Suppose that object A has methods a1,a2 and derivative AD adds a method ad1 how would one go about making a valid method chain of AD_instance.a1().a2().ad1(); ? Below are the two classes in question. Ignoring what it's actually doing, the method chaining is the only important part.

cannot find symbol “Embeddedrcall_Init”

岁酱吖の 提交于 2019-12-12 05:59:35
问题 I am trying to create a dll file using swig for an embeddedR C Program in windows environment. I am using the below commands: C:\swigwin-3.0.12\Examples\r\Z>swig -c++ -tcl embeddedRCall.i C:\swigwin-3.0.12\Examples\r\Z>gcc -c embeddedRCall.c -I/swigwin-3.0.12/Examples/r/Z C:\swigwin-3.0.12\Examples\r\Z>gcc -c embeddedRCall_wrap.c -I/Tcl/include/tcl8.6 -I/swigwin-3.0.12/Examples/r/Z C:\swigwin-3.0.12\Examples\r\Z>gcc -shared embeddedRCall.o embeddedRCall_wrap.o -o embeddedRCall.dll -L/Tcl/lib

Difference and conversions between wchar_t for Linux and for Windows

你。 提交于 2019-12-12 05:58:35
问题 I understand from this and this thread that in Windows, wchar_t is 16-bit & for Linux, wchar_t is 32 bit. I have a client-server architecture (using just pipes - not sockets)- where my server is Windows based and client is Linux. Server has a API to retrieve hostname from client. When the client is Windows based, it could just do GetComputerNameW and return Wide-String. However, when the client is Linux based, things get messy. As a first naive approach, I used mbstowcs() hoping to return

Where's g++'s VLA extension?

六月ゝ 毕业季﹏ 提交于 2019-12-12 05:38:20
问题 My question is related to this thread. Here is the code #include <stdio.h> int main(int argc, char *argv[printf("Hello, world!\n")]) {} I accidently saved it as a *.cpp file and tried to compile it with g++ . But I got an error and a warning. error: expected ',' or '...' before 'argv' warning: second argument of 'int main(int, char*)' should be 'char ** ' I know the above code is not Standard C++ [size of an array must be a constant expression in C++] but I always thought g++ supports Varible

Building (and running) RInside examples under windows

岁酱吖の 提交于 2019-12-12 05:37:20
问题 I am quite new to the RInside + Rcpp + R + C++ + windows story. I am trying to get things going by successfully compiling and running RInside examples. I managed to overcome many initial problems (like this one), and finally managed to build 64bit RInside example executables. I am running the newest version of R the newest version of RTools. I built RInside and RCPP from source by running install.packages(c("Rcpp","RInside"),type="source") Otherwise I was only able to build x86 binary (which

g++ -I duplicating libraries

让人想犯罪 __ 提交于 2019-12-12 04:57:35
问题 I'm learning to program C++ in Linux, and I have the following problem: I have 4 files: main.cpp, model.cpp, view.cpp and controller.cpp, each (except main) with their own header files. main.cpp includes model.h, view.h and controller.h, and view.h includes other libraries that are only relevant to it (necessary to run the graphic library). Those libraries are in different folders and have other dependencies on their own (that's why I don't want to move them). So, my makefile looks as follows

Address sanitizer failure

心已入冬 提交于 2019-12-12 04:56:33
问题 I'm using gcc and clang-embedded sanitizers for a little, including address sanitizer. And things work pretty well, but on next demo code I get no output related to a error despite it is there (to be more precise -- no output at all): #include <string> #include <iostream> using std::string; using std::cout; class Foo { string _member; public: Foo(): _member("just a string") {} const string& get() const { return _member; } }; const string& bar() { // returning reference to a temp object on