g++

Use static_assert to check types passed to macro

拜拜、爱过 提交于 2020-04-05 11:50:26
问题 I unfortunately have several macros left over from the original version of my library that employed some pretty crazy C. In particular, I have a series of macros that expect certain types to be passed to them. Is it possible to do something along the lines of: static_assert(decltype(retval) == bool); And how? Are there any clever alternatives? Yes I'm aware macros are bad. I'm aware C++ is not C, etc. Update0 Here is some related code, and the source file. Suggestions are welcome. The

g++ , range based for and vectorization

半腔热情 提交于 2020-03-24 04:56:42
问题 considering the following range based for loop in C++ 11 for ( T k : j ) { ... } there are g++ or clang++ optimization flags that can speed up the compiled code ? I'm not talking about any for cycle I'm only considering this new C++11 construct. 回答1: Optimizing loops is very rarely about optimizing the actual loop iteration code ( for ( T k : j ) in this case), but very much about optimizing what is IN the loop. Now, since this is ... in this case, it's impossible to say if, for example,

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.a when searching for -lstdc++ /usr/bin/ld: cannot find -lstdc++

会有一股神秘感。 提交于 2020-03-16 07:34:24
问题 why am i getting this error? g++ -m32 func.o test.o -o prgram /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.so when searching for -lstdc++ /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.a when searching for -lstdc++ /usr/bin/ld: cannot find -lstdc++ collect2: error: ld returned 1 exit status my code is as follows: #include<stdio.h> 2 3 4 extern "C" int calcsum(int a, int b, int c); 5 6 int main(int argc,char* argv[]) 7 { 8 int a =

G++ Undefined Reference std::

此生再无相见时 提交于 2020-03-16 06:00:48
问题 I've been working on porting one of my games to Linux and can't seem to figure out the reasons for the errors I'm received. The game was originally written in Visual Studio 2010 and I have extracted all of the needed content (headers, cpp, textures) and am trying to compile. Compilation of files using g++ -c -o exampleFile.o exampleFile.cpp works fine without any errors. However upon linking I am greeted with hundreds of errors regarding std functions, an example: Bmp.o: In function `Image:

Linaro g++ aarch64 compilation cause unalignment fault

白昼怎懂夜的黑 提交于 2020-03-04 05:20:34
问题 I'm using linaro g++ for ARM arch64 to compile a simple cpp file: int main() { char *helloMain = "main module (crm.c)"; long faculty, num = 12; int stop,mainLoop = 1; char word[80] = ""; } After objdump the generated elf file, I got its asm code: 0000000000001270 <main>: int main() { 1270: d101c3ff sub sp, sp, #0x70 char *helloMain = "main module (crm.c)"; 1274: 90000020 adrp x0, 5000 <_malloc_trim_r+0x160> 1278: 9111c000 add x0, x0, #0x470 127c: f90003e0 str x0, [sp] long faculty, num = 12;

std::string SSO tuning

杀马特。学长 韩版系。学妹 提交于 2020-03-02 05:56:46
问题 Is it possible to tune std::string Small/Short String Optimization somehow? For example, if I have to work with a lot of quite short strings but longer than 15 chars (like lastname + ", " + firstname + ", " + middlename which length is usually in range of [20; 40] ). Upd: According to this looks like the answer is no. But when I opened basic_string.h file I've found this: template<typename _CharT, typename _Traits, typename _Alloc> class basic_string { ... enum { _S_local_capacity = 15 /

link to external library with g++

梦想的初衷 提交于 2020-02-28 23:31:29
问题 I downloaded the FMUSDK and I want to compile the code. Unfortunately the build script is supposed to work with the Visual Studio C compiler, but I can't install/use it on my machine. Thus, I try to modify the script (and some parts of the code) to be able to compile it with the GCC. But I am completely new to compiling complex code (I usually just use gcc *.c -o outfile.exe) Here is my problem: In some files there is a library linked with #pragma comment(lib, "libxml2.lib") This does not

Make compiler assume that all cases are handled in switch without default

天大地大妈咪最大 提交于 2020-02-27 23:08:36
问题 Let's start with some code. This is an extremely simplified version of my program. #include <stdint.h> volatile uint16_t dummyColorRecepient; void updateColor(const uint8_t iteration) { uint16_t colorData; switch(iteration) { case 0: colorData = 123; break; case 1: colorData = 234; break; case 2: colorData = 345; break; } dummyColorRecepient = colorData; } // dummy main function int main() { uint8_t iteration = 0; while (true) { updateColor(iteration); if (++iteration == 3) iteration = 0; } }

field initializer is not constant g++ 4.8.4

核能气质少年 提交于 2020-02-25 13:14:09
问题 I tried to compile the following code on my laptop, using g++ 4.8.4: #include <algorithm> #include <iostream> #include <initializer_list> #include <tuple> struct Storage { static const int num_spatial_subset = 8; static constexpr std::initializer_list<std::initializer_list<double>> vectors{ {0,0,0}, {0,1,0}, {0,0,1}, {1,1,0}, {1,0,1}, {0,1,1}, {1,0,0}, {1,1,1} }; double storage[num_spatial_subset][vectors.size()]; }; int main() { } And I got this error message: error: field initializer is not

mingw32/bin/ld.exe … undefined reference to [class] … collect2.exe: error: ld returned 1 exit status

让人想犯罪 __ 提交于 2020-02-25 09:43:12
问题 Problem description while I am trying to move my code from Linux to Windows: MinGW on Windows linker problems happens when I am calling a user-defined class inside my Main.cpp ( works fine if I do not call the user-defined class constructor in Main ) Relevant code samples: Person.hpp class Person { public: Person(const string& iName, const list<string>& iContactDetails, ); virtual ~Person(); ... Main.cpp #include "Person.hpp" ... int main() { ... Person myPerson = Person (myName,