Git Product home page Git Product logo

Comments (5)

martinmoene avatar martinmoene commented on August 26, 2024

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.

jpcima avatar jpcima commented on August 26, 2024

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.

martinmoene avatar martinmoene commented on August 26, 2024

mmm, thanks @jpcima

Do you have

  1. an idea what would be a good approach for the test, preferably without determining the system's endianness?
  2. a hint for online testing with a big endian configuration?
  3. entirely different suggestions?

Thanks if you do.

from byte-lite.

jpcima avatar jpcima commented on August 26, 2024

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.

martinmoene avatar martinmoene commented on August 26, 2024

Ah, thank you :)

from byte-lite.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.