This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Possible bug in gcc 4.4.7


On 17 September 2014 17:16, Andy Falanga (afalanga) wrote:
> Flag operator &=(Flag& f1, Flag f2) {
>         return static_cast<Flag>(reinterpret_cast<unsigned int&>(f1) &= static_cast<unsigned int>(f2));
> }

That reinterpret_cast looks dodgy to me, accessing the object through
a different type is undefined behaviour. What's wrong with doing it
safely?

Flag operator &=(Flag& f1, Flag f2) {
  unsigned int i = f1;
  i &= static_cast<unsigned int>(f2);
  return f1 = static_cast<Flag>(i);
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]