gcc4

C++: nested class of a template class

喜你入骨 提交于 2019-11-28 10:55:33
Consider the following code: template < typename T > struct A { struct B { }; }; template < typename T > void f( typename A<T>::B ) { } int main() { A<int>::B x; f( x ); // fails for gcc-4.1.2 f<int>( x ); // passes return 0; } So here gcc-4.1.2 requires the template argument of f to be explicitly specified. Is this meet the standard? Does the newer versions of GCC have this issue fixed? How can I avoid explicitly specifying int while calling f ? Update: Here is a workaround. #include <boost/static_assert.hpp> #include <boost/type_traits/is_same.hpp> template < typename T > struct A { typedef

C-callback to function template: explicitly instantiate template

只愿长相守 提交于 2019-11-28 09:53:02
Premise I’m using a C library (from C++) which provides the following interface: void register_callback(void* f, void* data); void invoke_callback(); Problem Now, I need to register a function template as a callback and this is causing me problems. Consider the following code: template <typename T> void my_callback(void* data) { … } int main() { int ft = 42; register_callback(reinterpret_cast<void*>(&my_callback<int>), &ft); invoke_callback(); } This gives me the following linker error (using g++ (GCC) 4.5.1 on OS X but works on most other combinations of compiler version / platform ):

GCC 4.5 vs 4.4 linking with dependencies

徘徊边缘 提交于 2019-11-28 07:46:52
I am observing a difference when trying to do the same operation on GCC 4.4 and GCC 4.5. Because the code I am doing this with is proprietary, I am unable to provide it, but I am observing a similar failure with this simple test case. What I am basically trying to do is have one shared library (libb) depend on another shared library (liba). When loading libb, I assume that liba should be loaded as well - even though libb is not necessarily using the symbols in liba. What I am observing is when I compile with GCC 4.4, I observe that the liba is loaded, but if I compile with GCC 4.5, libb is not

(Not So) Silly Objective-C inheritance problem when using property - GCC Bug?

六月ゝ 毕业季﹏ 提交于 2019-11-27 20:43:25
Update - Many people are insisting I need to declare an iVar for the property. Some are saying not so, as I am using Modern Runtime (64 bit). I can confirm that I have been successfully using @property without iVars for months now. Therefore, I think the 'correct' answer is an explanation as to why on 64bit I suddenly have to explicitly declare the iVar when (and only when) i'm going to access it from a child class. The only one I've seen so far is a possible GCC bug (thanks Yuji). Not so simple after all... To clarify the possible bug is this: When inheriting from a base class, a child can

Why does sqrt() work fine on an int variable if it is not defined for an int?

安稳与你 提交于 2019-11-27 16:07:58
In chapter 3 of Programming: Principles and Practice using C++ (sixth printing), Stroustrup states (p.68): "Note that sqrt() is not defined for an int " . Here is a simple C++ program based on that chapter: #include "std_lib_facilities.h" int main() { int n = 3; cout << "Square root of n == " << sqrt(n) << "\n"; } Given the quote above, I would expect the process of compiling or running this program to fail in some way. To my surprise, compiling it (with g++ (GCC) 4.2.1) and running it succeeded without errors or warnings, and produced the following perfectly decent output: Square root of n ==

How to get CMake to pass either std=c++14/c++1y or c++17/c++1z based on GCC version?

空扰寡人 提交于 2019-11-27 12:55:38
问题 GCC 4.x doesn't accept the --std=c++14 switch for C++14 code - it takes --std=c++1y instead. Later versions take --std=c++1z but (probably) not --std=c++17 which has not been set yet (writing this in 2016). Perhaps there are similar issues with C++11. Does CMake have some facility (perhaps as a module) to pass the correct switch according to the GCC version? 回答1: When wanting to specify a particular C++ version, the recommended way to do this with CMake 3.1 and later is to use the CXX

C++: nested class of a template class

☆樱花仙子☆ 提交于 2019-11-27 03:54:37
问题 Consider the following code: template < typename T > struct A { struct B { }; }; template < typename T > void f( typename A<T>::B ) { } int main() { A<int>::B x; f( x ); // fails for gcc-4.1.2 f<int>( x ); // passes return 0; } So here gcc-4.1.2 requires the template argument of f to be explicitly specified. Is this meet the standard? Does the newer versions of GCC have this issue fixed? How can I avoid explicitly specifying int while calling f ? Update: Here is a workaround. #include <boost

GCC 4.5 vs 4.4 linking with dependencies

China☆狼群 提交于 2019-11-27 02:03:33
问题 I am observing a difference when trying to do the same operation on GCC 4.4 and GCC 4.5. Because the code I am doing this with is proprietary, I am unable to provide it, but I am observing a similar failure with this simple test case. What I am basically trying to do is have one shared library (libb) depend on another shared library (liba). When loading libb, I assume that liba should be loaded as well - even though libb is not necessarily using the symbols in liba. What I am observing is

memory alignment within gcc structs

泄露秘密 提交于 2019-11-27 01:10:23
I am porting an application to an ARM platform in C, the application also runs on an x86 processor, and must be backward compatible. I am now having some issues with variable alignment. I have read the gcc manual for __attribute__((aligned(4),packed)) I interpret what is being said as the start of the struct is aligned to the 4 byte boundry and the inside remains untouched because of the packed statement. originally I had this but occasionally it gets placed unaligned with the 4 byte boundary. typedef struct { unsigned int code; unsigned int length; unsigned int seq; unsigned int request;

memory alignment within gcc structs

时光总嘲笑我的痴心妄想 提交于 2019-11-26 09:37:47
问题 I am porting an application to an ARM platform in C, the application also runs on an x86 processor, and must be backward compatible. I am now having some issues with variable alignment. I have read the gcc manual for __attribute__((aligned(4),packed)) I interpret what is being said as the start of the struct is aligned to the 4 byte boundry and the inside remains untouched because of the packed statement. originally I had this but occasionally it gets placed unaligned with the 4 byte boundary