g++

c++ bit fields and -Wconversion

試著忘記壹切 提交于 2020-01-01 08:52:54
问题 -Wconversion is producing warnings when I assign a value to a bit field with g++. Source file: struct Foo { public: unsigned int x : 4; unsigned int y : 9; unsigned int z : 17; }; int main(int, char**) { int a = 12; Foo f; f.x = a; f.x = (unsigned int)a; f.x = (unsigned char)a; f.x = (unsigned short)a; f.x = (unsigned)a; f.y = a; f.y = (unsigned int)a; f.y = (unsigned char)a; // no warning, sizeof(char) < 9 f.y = (unsigned short)a; f.y = (unsigned)a; f.z = a; f.z = (unsigned int)a; f.z =

Why code using local struct as parameter for STL function does not compile in g++?

拟墨画扇 提交于 2020-01-01 08:33:30
问题 I have such code which works well: #include <algorithm> #include <iostream> char x[11]= "ABCDEFGHIJ"; char y[11]; struct F { char operator () (char c) const { return c+1; } }; int main() { std::transform(x, x+10, y, F()); y[10] = 0; std::cout <<y <<std::endl; } But if I change it to this style: #include <algorithm> #include <iostream> char x[11]= "ABCDEFGHIJ"; char y[11]; int main() { struct F { char operator () (char c) const { return c+1; } }; std::transform(x, x+10, y, F()); y[10] = 0; std

Why code using local struct as parameter for STL function does not compile in g++?

旧城冷巷雨未停 提交于 2020-01-01 08:33:00
问题 I have such code which works well: #include <algorithm> #include <iostream> char x[11]= "ABCDEFGHIJ"; char y[11]; struct F { char operator () (char c) const { return c+1; } }; int main() { std::transform(x, x+10, y, F()); y[10] = 0; std::cout <<y <<std::endl; } But if I change it to this style: #include <algorithm> #include <iostream> char x[11]= "ABCDEFGHIJ"; char y[11]; int main() { struct F { char operator () (char c) const { return c+1; } }; std::transform(x, x+10, y, F()); y[10] = 0; std

gdb on mac 10.9 fails with “not in executable format: File format not recognized” for 32+64 arch

风流意气都作罢 提交于 2020-01-01 08:18:29
问题 $ file app app: Mach-O universal binary with 2 architectures app (for architecture i386): Mach-O executable i386 app (for architecture x86_64): Mach-O 64-bit executable x86_64 $ gdb app GNU gdb (GDB) 7.6 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for

gdb on mac 10.9 fails with “not in executable format: File format not recognized” for 32+64 arch

自古美人都是妖i 提交于 2020-01-01 08:18:09
问题 $ file app app: Mach-O universal binary with 2 architectures app (for architecture i386): Mach-O executable i386 app (for architecture x86_64): Mach-O 64-bit executable x86_64 $ gdb app GNU gdb (GDB) 7.6 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for

Unknown type name ‘off64_t’

空扰寡人 提交于 2020-01-01 07:59:29
问题 I have a problem using Apache Portable Runtime on Ubuntu with GCC 4.8.1 The problem is that the off64_t from <sys/types.h> is not available when compiling with gcc . (When compiling with g++ everything work fine) Does anybody know which compiler switch to use to enable off64_t ? (I know that defining _LARGEFILE_SOURCE _LARGEFILE64_SOURCE avoids the problem, but wondering if this is the right way) To reproduce the error one can simply try to compile the following code: #include <sys/types.h>

“expected type-specifier” error in g++

倾然丶 夕夏残阳落幕 提交于 2020-01-01 07:24:06
问题 I have a DD class template<typename T> class DD : public IEnumerable<T> { typedef IEnumerable<T> Super; typedef std::set<T*> Container; And a method template<typename T> bool DD<T>::Enumerator::Move() { if(!mIt.get()) mIt.reset( new Container::iterator( <----- mContainer.GetContainer().begin() ) ); ... } When I compile the class, I got error: expected type-specifier . What's wrong with the Container::iterator() ? 回答1: Try: new typename Container::iterator When you are in a C++ template, the

How do I set GNU G++ compiler in Visual studio 2008

↘锁芯ラ 提交于 2020-01-01 06:14:29
问题 How do I set my Visual studio 2008 compiler to GNU GCC. Can I also make it specific to projects? I didn't find any conclusive answer. Thank you. 回答1: You can't use the compiler directly. You can, however, invoke a makefile instead of using the built-in build system. Example of configuration: Install MinGW (I guess this step is already done), including mingw32-make Create a makefile for mingw32-make called MinGWMakefile , with 3 targets: clean , build , and rebuild . This can be very tedious

How do I set GNU G++ compiler in Visual studio 2008

夙愿已清 提交于 2020-01-01 06:14:11
问题 How do I set my Visual studio 2008 compiler to GNU GCC. Can I also make it specific to projects? I didn't find any conclusive answer. Thank you. 回答1: You can't use the compiler directly. You can, however, invoke a makefile instead of using the built-in build system. Example of configuration: Install MinGW (I guess this step is already done), including mingw32-make Create a makefile for mingw32-make called MinGWMakefile , with 3 targets: clean , build , and rebuild . This can be very tedious

“Undefined reference to” Error while linking object files [duplicate]

不羁岁月 提交于 2020-01-01 05:17:07
问题 This question already has an answer here : “undefined reference to” errors when linking static C library with C++ code (1 answer) Closed 3 years ago . I realize this question has been asked in a number of ways including this very comprehensive answer but I have looked at many and tried fixing my error to no avail. I am using .cpp and .c files to create a program. I compiled all files with g++, it seemed to have no more linking errors, though it gave me a bunch of C++ errors related to the C