Unsigned int behaves differently in Release Mode

1

I have a weird problem, in Debug Mode this code works fine:

char* PCInformation::GetCPUName()
{
    if (CPUName[0] == '\0')
    {
        _memset(CPUName, 0, 0x3F);
        // Get extended ids.
        int CPUInfo[4] = {-1};
        __cpuid(CPUInfo, 0x80000000);
        unsigned int nExIds = CPUInfo[0];

        printf(3, "%d\n%d\n", nExIds, 0x80000000);

        // Get the information associated with each extended ID.
        for(unsigned int i=0x80000000; i<=nExIds; ++i)
        {
            printf(3, "0x80000000 nExIds: %X, i: %X\n", nExIds, i);
            getchar();
            __cpuid(CPUInfo, i);

            // Interpret CPU brand string and cache information.
            if  (i == 0x80000002)
            {
                _memcpy( CPUName,
                CPUInfo,
                sizeof(CPUInfo));
            }
            else if( i == 0x80000003 )
            {
                _memcpy( CPUName + 16,
                CPUInfo,
                sizeof(CPUInfo));
            }
            else if( i == 0x80000004 )
            {
                _memcpy(CPUName + 32, CPUInfo, sizeof(CPUInfo));
            }
        }
    }

    return CPUName;
}

Source: http://weseetips.com/2009/06/21/how-to-get-the-cpu-name-string/

Edit: (this is how _functions looks like)

BOOL CallDynamic(const char* szModule, const char* szFunction, DWORD* dwReturn, size_t argc, ... );
#define printf(argc, ... ) (CallDynamic(MSVCRT, "printf", NULL, argc, __VA_ARGS__ )) //number arguments, arguments

If you wonder why there are _ for the STD-C Functions, its because they are called dynamically, but that is not the problem. (Because the same code used to work fine, but I put it in a class and bahm!)

Anyway if I choose Release (as Build Mode) (int) i contains some weird value or something. For more declaration some pictures:

Release Release Build

Debug Debug Build In release it ends up with infinite for-loop.

Edit: I just changed the code to:

char* PCInformation::GetCPUName()
{
    if (CPUName[0] == '\0')
    {
        _memset(CPUName, 0, 0x3F);

        int CPUInfo[4];
        _memset(CPUInfo, 0, 4);

        __cpuid(CPUInfo, 0x80000000);
        _memcpy(CPUName, CPUInfo, sizeof(CPUInfo));

        __cpuid(CPUInfo, 0x80000002);
        _memcpy(CPUName + 16, CPUInfo, sizeof(CPUInfo));

        __cpuid(CPUInfo, 0x80000003);
        _memcpy(CPUName + 32, CPUInfo, sizeof(CPUInfo));

        __cpuid(CPUInfo, 0x80000004);
        _memcpy(CPUName + 48, CPUInfo, sizeof(CPUInfo));
    }

    return CPUName;
}

Altho I still like to know what is causing it.

Regards,

c++
visual-studio-2012
unsigned-integer
cpuid
asked on Stack Overflow Feb 13, 2013 by joell • edited Feb 13, 2013 by joell

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0