I don't think that casting a range of bits as some other arbitrary type "is a bug nobody sees coming".

C++ compilers also warn you that this is likely an issue and will fail to compile if configured to do so. But it will let you do it if you really want to.

That's why I love C++

a screenshot from linkedin reading "I don't think that casting a range of bits as some other arbitrary type "is a bug nobody sees coming". C++ compilers also warn you that this is likely an issue and will fail to compile if configured to do so. But it will *let you do it* if you really want to. That's why I love C++"
you are viewing a single comment's thread
view the rest of the comments
[–] 1 point 1 year ago (4 children)

You use it to "pack" bitfields, bytes etc together in structs/classes (wo functions), otherwise the computer usually align every variable on a 32bit boundary for speed.

  • source
  • parent
  • hideshow 4 child comments
  • [–] 1 point 1 year ago (3 children)

    You don't need that pragma to pack bitfields.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 2 points 1 year ago* (last edited 1 year ago) (2 children)

    With say a 3bit int, then a 2bit int and various char, int etc and so on you did have to use the pragma with gcc & visual around 2012 at least

  • source
  • parent
  • hideshow 2 child comments