F
Francesco
Hi to all,
would any of you gentlemen please comment on the reinterpret_casts in
the code below?
Do you think they're ok or not? Any reference to the standard would be
greatly appreciated.
Thank in advance,
FB
//CODE
#include <iostream>
#include <iomanip>
typedef float ( * tMtx )[ 4 ];
void Fill( tMtx inMtx )
{
for( int c = 0; c < 16; ++c )
inMtx[ c / 4 ][ c % 4 ] = c;
}
void Print( tMtx inMtx )
{
std::cout << "n->" << inMtx << std::endl;
for( int c1 = 0; c1 < 4; ++c1 )
{
for( int c2 = 0; c2 < 4; ++c2 )
std::cout << std::setw( 5 ) << inMtx[ c1 ][ c2 ];
std::cout << std::endl;
}
std::cout << std::endl;
}
int main()
{
float mtx1[ 16 ] = { 0 };
float mtx2[ 4 ][ 4 ];
float * mtx3 = new float[ 16 ];
float * mtx4 = reinterpret_cast< float * >( new float[ 4 ][ 4 ] );
// are these casts OK?
Fill( reinterpret_cast< tMtx >( mtx1 ) );
Fill( mtx2 );
Fill( reinterpret_cast< tMtx >( mtx3 ) );
Fill( reinterpret_cast< tMtx >( mtx4 ) );
Print( reinterpret_cast< tMtx >( mtx1 ) );
Print( mtx2 );
Print( reinterpret_cast< tMtx >( mtx3 ) );
Print( reinterpret_cast< tMtx >( mtx4 ) );
delete[] mtx3;
delete[] mtx4;
std::cin.get();
}
//ENDCODE
would any of you gentlemen please comment on the reinterpret_casts in
the code below?
Do you think they're ok or not? Any reference to the standard would be
greatly appreciated.
Thank in advance,
FB
//CODE
#include <iostream>
#include <iomanip>
typedef float ( * tMtx )[ 4 ];
void Fill( tMtx inMtx )
{
for( int c = 0; c < 16; ++c )
inMtx[ c / 4 ][ c % 4 ] = c;
}
void Print( tMtx inMtx )
{
std::cout << "n->" << inMtx << std::endl;
for( int c1 = 0; c1 < 4; ++c1 )
{
for( int c2 = 0; c2 < 4; ++c2 )
std::cout << std::setw( 5 ) << inMtx[ c1 ][ c2 ];
std::cout << std::endl;
}
std::cout << std::endl;
}
int main()
{
float mtx1[ 16 ] = { 0 };
float mtx2[ 4 ][ 4 ];
float * mtx3 = new float[ 16 ];
float * mtx4 = reinterpret_cast< float * >( new float[ 4 ][ 4 ] );
// are these casts OK?
Fill( reinterpret_cast< tMtx >( mtx1 ) );
Fill( mtx2 );
Fill( reinterpret_cast< tMtx >( mtx3 ) );
Fill( reinterpret_cast< tMtx >( mtx4 ) );
Print( reinterpret_cast< tMtx >( mtx1 ) );
Print( mtx2 );
Print( reinterpret_cast< tMtx >( mtx3 ) );
Print( reinterpret_cast< tMtx >( mtx4 ) );
delete[] mtx3;
delete[] mtx4;
std::cin.get();
}
//ENDCODE