E
Edoardo Tagome
Hi,
as usual I need your help to understand if a strange behaviour (in my
opinion) that android ndk gcc compiler show... comes from a compiler bug
or is a consequence of a undefined behaviour(?) that's a consequence of
my bad coding
I only want to say that under windows (both VS2010 and mingw gcc4.7) the
behaviour is what I would expect (i.e. is correct form me).
As you can see (below OUTPUT) it seemd that under android there are two
instances of template class attibutes (mInt and mMap) where I would
expect only one (as in Windows).
In particular it seems to me that the references are considered a
different type than the referenced one (ok... somewhat :-D ).
BLABLABLA... meand I've substituted some long unuseful output with this
As usual Thanks in advance!!! And I'm eager to know if and what I've
done wrong
// For Android
#define MAGO_LOG_METHOD_DEBUG_PTR( aStr, aPtr ) \
__android_log_print( \
ANDROID_LOG_DEBUG , \
APPNAME , \
"%s %s %d %s %p" , \
__PRETTY_FUNCTION__ , \
__FILE__ , \
__LINE__ , \
aStr , \
aPtr \
)
// For Windows
#define MAGO_LOG_METHOD_DEBUG_PTR( aStr, aPtr ) \
std::cout << \
APPNAME << " " << \
__FUNCTION__ << " " << \
__FILE__ << " " << \
__LINE__ << " " << \
aStr << \
aPtr << " " << \
std::endl
---- MaGoTest.hpp BEGIN ----
// Bas
template <class T>
class Bas
{
public:
static void PrintAddresses( void )
{
MAGO_LOG_METHOD_DEBUG_PTR( "&mInt=" , &mInt ) ;
MAGO_LOG_METHOD_DEBUG_PTR( "&mMap=" , &mMap ) ;
}
protected:
static int mInt ;
static std::map< T * , std::shared_ptr< T > > mMap ;
} ;
template<class T>
int Bas<T>::mInt = 0 ;
template<class T>
std::map<T * , std::shared_ptr< T >> Bas<T>::mMap ;
// Deri
class Deri : public Bas< Deri >
{
public:
Deri() ;
} ;
// Printer
class Printer
{
public:
static void Print( Deri & aInstance ) ;
} ;
---- MaGoTest.hpp END ----
---- MaGoTest.cpp BEGIN ----
Deri:eri()
{
std::cout << "Deri constructor" << std::endl ;
}
void Printer:rint( Deri & aInstance )
{
aInstance.PrintAddresses() ;
}
---- MaGoTest.cpp END ----
---- main.cpp BEGIN ----
#include "MaGoTest.hpp"
int main( void )
{
Deri _firstDeri ;
_firstDeri.PrintAddresses() ;
Deri _secondDeri ;
_secondDeri.PrintAddresses() ;
Printer:rint( _firstDeri ) ;
Printer:rint( _secondDeri ) ;
return 0 ;
}
---- main.cpp END ----
---- OUTPUT Android ----
// Deri constructor should be here (is not logged)
09-17 19:46:35.290: D/MaGo(13708): static void Bas<T>:rintAddresses()
[with T = Deri] BLABLABLA... MaGoTest.hpp 59 &mInt= 0x5c99137c
// Deri constructor should be here (is not logged)
09-17 19:46:35.290: D/MaGo(13708): static void Bas<T>:rintAddresses()
[with T = Deri] BLABLABLA... MaGoTest.hpp 60 &mMap= 0x5c991360
09-17 19:46:35.290: D/MaGo(13708): static void Bas<T>:rintAddresses()
[with T = Deri] BLABLABLA... MaGoTest.hpp 59 &mInt= 0x5c99137c
09-17 19:46:35.290: D/MaGo(13708): static void Bas<T>:rintAddresses()
[with T = Deri] BLABLABLA... MaGoTest.hpp 60 &mMap= 0x5c991360
09-17 19:46:35.290: D/MaGo(13708): static void Bas<T>:rintAddresses()
[with T = Deri] BLABLABLA... /MaGoTest.hpp 59 &mInt= 0x5c01a174 //(2nd
instance: STRANGE )
09-17 19:46:35.290: D/MaGo(13708): static void Bas<T>:rintAddresses()
[with T = Deri] BLABLABLA... MaGoTest.hpp 60 &mMap= 0x5c01a158 //(2nd
instance: STRANGE )
09-17 19:46:35.290: D/MaGo(13708): static void Bas<T>:rintAddresses()
[with T = Deri] BLABLABLA... MaGoTest.hpp 59 &mInt= 0x5c01a174
09-17 19:46:35.290: D/MaGo(13708): static void Bas<T>:rintAddresses()
[with T = Deri] BLABLABLA... MaGoTest.hpp 60 &mMap= 0x5c01a158
---- OUTPUT Android END ----
---- OUTPUT Windows ----
Deri constructor
MaGo PrintAddresses BLABLABLA... MaGoTest.hpp 59 &mInt=0x405018 //(1
instance: CORRECT )
MaGo PrintAddresses BLABLABLA... MaGoTest.hpp 60 &mMap=0x40501c //(1
instance: CORRECT )
Deri constructor
MaGo PrintAddresses BLABLABLA... MaGoTest.hpp 59 &mInt=0x405018
MaGo PrintAddresses BLABLABLA... MaGoTest.hpp 60 &mMap=0x40501c
MaGo PrintAddresses BLABLABLA... MaGoTest.hpp 59 &mInt=0x405018
MaGo PrintAddresses BLABLABLA... MaGoTest.hpp 60 &mMap=0x40501c
MaGo PrintAddresses BLABLABLA... MaGoTest.hpp 59 &mInt=0x405018
MaGo PrintAddresses BLABLABLA... MaGoTest.hpp 60 &mMap=0x40501c
---- OUTPUT Windows END ----
as usual I need your help to understand if a strange behaviour (in my
opinion) that android ndk gcc compiler show... comes from a compiler bug
or is a consequence of a undefined behaviour(?) that's a consequence of
my bad coding
I only want to say that under windows (both VS2010 and mingw gcc4.7) the
behaviour is what I would expect (i.e. is correct form me).
As you can see (below OUTPUT) it seemd that under android there are two
instances of template class attibutes (mInt and mMap) where I would
expect only one (as in Windows).
In particular it seems to me that the references are considered a
different type than the referenced one (ok... somewhat :-D ).
BLABLABLA... meand I've substituted some long unuseful output with this
As usual Thanks in advance!!! And I'm eager to know if and what I've
done wrong
// For Android
#define MAGO_LOG_METHOD_DEBUG_PTR( aStr, aPtr ) \
__android_log_print( \
ANDROID_LOG_DEBUG , \
APPNAME , \
"%s %s %d %s %p" , \
__PRETTY_FUNCTION__ , \
__FILE__ , \
__LINE__ , \
aStr , \
aPtr \
)
// For Windows
#define MAGO_LOG_METHOD_DEBUG_PTR( aStr, aPtr ) \
std::cout << \
APPNAME << " " << \
__FUNCTION__ << " " << \
__FILE__ << " " << \
__LINE__ << " " << \
aStr << \
aPtr << " " << \
std::endl
---- MaGoTest.hpp BEGIN ----
// Bas
template <class T>
class Bas
{
public:
static void PrintAddresses( void )
{
MAGO_LOG_METHOD_DEBUG_PTR( "&mInt=" , &mInt ) ;
MAGO_LOG_METHOD_DEBUG_PTR( "&mMap=" , &mMap ) ;
}
protected:
static int mInt ;
static std::map< T * , std::shared_ptr< T > > mMap ;
} ;
template<class T>
int Bas<T>::mInt = 0 ;
template<class T>
std::map<T * , std::shared_ptr< T >> Bas<T>::mMap ;
// Deri
class Deri : public Bas< Deri >
{
public:
Deri() ;
} ;
// Printer
class Printer
{
public:
static void Print( Deri & aInstance ) ;
} ;
---- MaGoTest.hpp END ----
---- MaGoTest.cpp BEGIN ----
Deri:eri()
{
std::cout << "Deri constructor" << std::endl ;
}
void Printer:rint( Deri & aInstance )
{
aInstance.PrintAddresses() ;
}
---- MaGoTest.cpp END ----
---- main.cpp BEGIN ----
#include "MaGoTest.hpp"
int main( void )
{
Deri _firstDeri ;
_firstDeri.PrintAddresses() ;
Deri _secondDeri ;
_secondDeri.PrintAddresses() ;
Printer:rint( _firstDeri ) ;
Printer:rint( _secondDeri ) ;
return 0 ;
}
---- main.cpp END ----
---- OUTPUT Android ----
// Deri constructor should be here (is not logged)
09-17 19:46:35.290: D/MaGo(13708): static void Bas<T>:rintAddresses()
[with T = Deri] BLABLABLA... MaGoTest.hpp 59 &mInt= 0x5c99137c
// Deri constructor should be here (is not logged)
09-17 19:46:35.290: D/MaGo(13708): static void Bas<T>:rintAddresses()
[with T = Deri] BLABLABLA... MaGoTest.hpp 60 &mMap= 0x5c991360
09-17 19:46:35.290: D/MaGo(13708): static void Bas<T>:rintAddresses()
[with T = Deri] BLABLABLA... MaGoTest.hpp 59 &mInt= 0x5c99137c
09-17 19:46:35.290: D/MaGo(13708): static void Bas<T>:rintAddresses()
[with T = Deri] BLABLABLA... MaGoTest.hpp 60 &mMap= 0x5c991360
09-17 19:46:35.290: D/MaGo(13708): static void Bas<T>:rintAddresses()
[with T = Deri] BLABLABLA... /MaGoTest.hpp 59 &mInt= 0x5c01a174 //(2nd
instance: STRANGE )
09-17 19:46:35.290: D/MaGo(13708): static void Bas<T>:rintAddresses()
[with T = Deri] BLABLABLA... MaGoTest.hpp 60 &mMap= 0x5c01a158 //(2nd
instance: STRANGE )
09-17 19:46:35.290: D/MaGo(13708): static void Bas<T>:rintAddresses()
[with T = Deri] BLABLABLA... MaGoTest.hpp 59 &mInt= 0x5c01a174
09-17 19:46:35.290: D/MaGo(13708): static void Bas<T>:rintAddresses()
[with T = Deri] BLABLABLA... MaGoTest.hpp 60 &mMap= 0x5c01a158
---- OUTPUT Android END ----
---- OUTPUT Windows ----
Deri constructor
MaGo PrintAddresses BLABLABLA... MaGoTest.hpp 59 &mInt=0x405018 //(1
instance: CORRECT )
MaGo PrintAddresses BLABLABLA... MaGoTest.hpp 60 &mMap=0x40501c //(1
instance: CORRECT )
Deri constructor
MaGo PrintAddresses BLABLABLA... MaGoTest.hpp 59 &mInt=0x405018
MaGo PrintAddresses BLABLABLA... MaGoTest.hpp 60 &mMap=0x40501c
MaGo PrintAddresses BLABLABLA... MaGoTest.hpp 59 &mInt=0x405018
MaGo PrintAddresses BLABLABLA... MaGoTest.hpp 60 &mMap=0x40501c
MaGo PrintAddresses BLABLABLA... MaGoTest.hpp 59 &mInt=0x405018
MaGo PrintAddresses BLABLABLA... MaGoTest.hpp 60 &mMap=0x40501c
---- OUTPUT Windows END ----