Re: pragma pack and bitfields

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: David Lowndes (davidl_at_example.invalid)
Date: 09/27/04


Date: Mon, 27 Sep 2004 11:07:12 +0100


>-----------------------------------------------
>enum State { ZERO, ONE, TWO };
>
>struct A {
> State s : 2;
>};
>
>void foo(A a) {
> a.s = TWO;
> if (a.s != TWO)
> abort();
>}
>-----------------------------------------------
>
>This aborts. The reason has surely to do with the underlying integer type of
>the bitfield being signed, so that basically 's' represents "-2" after
>assignment, and fails the comparison with two. Do you have a workaround for a
>situation like this?

Other than not using the enum as the bitfield type or otherwise
fiddling with the value, I'm afraid not.

>GCC works as expected.

I can imagine reasons for both possibilities, but I'm not familiar
enough with the C++ standards to know what it really should be.

Carl, can you comment on this?

Dave

-- 
MVP VC++ FAQ: http://www.mvps.org/vcfaq


Relevant Pages

  • Re: PTHREAD_MUTEX_INITIALIZER
    ... so it must be thread-safe. ... reason internal to the implementation, so you need to check the return ... pthread_mutex_lock fails. ... Guess what many 'abort' implementations ...
    (comp.programming.threads)
  • Re: Thread Abort
    ... Actualy I know about this API, But I don't know can I call it from my C# ... BOOL TerminateThread( ... and I can't wait until Abort finish his job, ... There are a lot of reason in our ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: death penalty
    ... allowing abortion would clamor just as quickly if a different ... religion that they did not believe was FORCED upon them. ... An unwanted child is as just as any other reason. ... family to not abort. ...
    (alt.fan.harry-potter)
  • Re: Where to request new function ?
    ... For instance, right now the openSuSE ... build server seems to be temporarily unaccessible. ... something similar to abort the process. ... installation sources and for some reason you want to halt the ...
    (alt.os.linux.suse)
  • RE: Thread Abort
    ... there should be no reason why you cannot abort a suspended thread, ... Even calling Abort on a thread does not guarantee that the thread will ... you may go into many regions of code befoer the thread is officially aborted. ...
    (microsoft.public.dotnet.languages.csharp)