CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004
    Location
    Near Portland, OR
    Posts
    222

    enum Creating Void Pointers at Runtime

    Maybe I'm missing something, but I've come across a head scratcher. I'm using enums to create numerics used in many places in my program. All the enums are in the same file.

    At runtime, the values in one enum show up as void * in the debugger, but they are normal numerics for the other enums. I did the declarations identically for all of them.

    This one produced the void *:

    Code:
    enum ClientState_e
    {
        CX_UNKNOWN=0,
        CX_CONTACT,
        CX_CONSULT,
        CX_PREFILE,
        CX_ACTIVE7,
        CX_ACTIVE13,
        CX_SUCCESSFUL7,
        CX_DISMISSED7,
        CX_INPLAN13,
        CX_DISMISSED13,
        CX_COMPLETE13,
        CX_COLDCONTACTS,
        CX_OLDCLIENTS,
        CX_MISC,
        CX_NUMMODES
    };
    Ths one is one of the many that produce normal numerics (TB_CLIENT==0, TB_INITCONSULT==1, etc.):

    Code:
    enum TabID_e
    {
        TB_CLIENT=0,
        TB_INITCONSULT,
        TB_PREFILE,
        TB_CH7OPEN,
        TB_CH13OPEN,
        TB_CH13PLAN,
        TB_MAXTAB
    };
    I double checked that the zero is a zero and not a capital 'o' and I don't see any differences in declaration that would cause anything to be different. When I mouse over the values in the editor, it says the CX_s are constants, 0, 1, 2, etc.

    Have I run into a compiler bug, or have I done something weird that I'm not seeing?

    Bill

  2. #2
    Join Date
    Jan 2004
    Location
    Near Portland, OR
    Posts
    222

    Re: enum Creating Void Pointers at Runtime

    OK I figured it out. I'll detail what happened in case anybody comes across this same issue someday.

    Turns out it was the way I was using them. I created a switch statement and forgot the case in front of the constants. When I changed them to #defines, I got compiler errors. For some reason the compiler didn't flag that as an error when they were enums.

    Anyway, case closed.

    Bill

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: enum Creating Void Pointers at Runtime

    I guess the compiler was interpreting them as goto labels before?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured