Comments (5)
Thanks @jpcima, the particular test is endian-dependent and wrong for big-endian configurations.
CASE( "byte: Allows strict aliasing" )
{
struct F {
static int f( int & i, nonstd::byte & r )
{
i = 7;
r <<= 1;
return i;
}
};
int i;
EXPECT( 14 == F::f( i, reinterpret_cast<nonstd::byte&>( i ) ) );
}
Pondering how to make it endian-independent...
from byte-lite.
Thanks @martinmoene.
It would appear however that this modification still hasn't fixed the problem.
1/4 Test #1: test-cpp98 .......................***Failed 0.00 sec
/builddir/build/BUILD/byte-lite-0.3.0/test/byte.t.cpp:207: failed: byte: Allows strict aliasing: (r == 0x0E || 0x0E00 == r) for false
1 out of 19 selected tests failed.
from byte-lite.
mmm, thanks @jpcima
Do you have
- an idea what would be a good approach for the test, preferably without determining the system's endianness?
- a hint for online testing with a big endian configuration?
- entirely different suggestions?
Thanks if you do.
from byte-lite.
The following runs with success.
What do you think about it?
CASE( "byte: Allows strict aliasing" )
{
struct F {
static int f( int & i, nonstd::byte & r )
{
r <<= 1;
return i;
}
};
int i = 7;
unsigned char& first = reinterpret_cast<unsigned char&>( i );
unsigned char& last = *( reinterpret_cast<unsigned char*>( &i ) + sizeof(int) - 1 );
bool little = ( first == 7 ) && ( last == 0 );
bool big = ( first == 0 ) && ( last == 7 );
EXPECT( (little ^ big) );
unsigned char& lsb = little ? first : last;
EXPECT( 14 == F::f( i, reinterpret_cast<nonstd::byte&>( lsb ) ) );
}
from byte-lite.
Ah, thank you :)
from byte-lite.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from byte-lite.