dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,465

    Value of UINT64_MAX ?

    I'm compiling some cross-platform code which has a test for UINTPTR_MAX, looking like this:-

    Code:
          #  if (UINTPTR_MAX == 0xFFFFFFFF)
          #    define LG_SIZEOF_PTR 4
          #  elif (UINTPTR_MAX == 0xFFFFFFFFFFFFFFFF)
          #    define LG_SIZEOF_PTR 8
          #  endif
    but for VS2015 Community Edition, stdint.h seems to define UNITPTR_MAX like this:-

    Code:
        #define UINT64_MAX       0xffffffffffffffffui64
    
        // some stuff...
    
        #define UINTPTR_MAX  UINT64_MAX
    It looks as if 0xFFFFFFFFFFFFFFFF and 0xffffffffffffffffui64 aren't being detected as the same number. Does that make sense to anyone..?
    "A problem well stated is a problem half solved. - Charles F. Kettering

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,213

    Re: Value of UINT64_MAX ?

    Don't know about VS2015, but for VS2017 the value of UINTPTR_MAX assigned depends upon whether _WIN64 is defined or not. If _WIN64 is defined then UINPTR_MAX becomes UINT64_MAX otherwise becomes UINT32_MAX.

    What value of LG_SIZEOF_PTR are you getting?

    This check works OK on my VS2017. When _WIN64 is defined, LG_SIZEOF_PTR is set to 8 and when _WIN64 is not defined it is set to 4.

    Are you using Visual Studio IDE? If so you should be able to see highlighted what parts of the preprocessor statements are true and which are not. Try changing temporarily

    Code:
    # if (UINTPTR_MAX == 0xFFFFFFFF)
    #    define LG_SIZEOF_PTR 4
    #  elif (UINTPTR_MAX == 0xFFFFFFFFFFFFFFFF)
    #    define LG_SIZEOF_PTR 8
    #  endif
    to

    Code:
    # if (UINT64_MAX == 0xFFFFFFFF)
    #    define LG_SIZEOF_PTR 4
    #  elif (UINT64_MAX == 0xFFFFFFFFFFFFFFFF)
    #    define LG_SIZEOF_PTR 8
    #  endif
    and see what LG_SIZEOF_PTR now becomes.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.7.2)

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,213

    Re: Value of UINT64_MAX ?

    Tried it now with VS2015. VS2015 requires an #include <stdint.h> whereas VS2017 doesn't seem to if #include <Windows.h> is also used. However, with the include VS2015 seems to work as expected.
    Last edited by 2kaud; April 30th, 2018 at 11:30 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.7.2)

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,213

    Re: Value of UINT64_MAX ?

    This is the test code used with VS2015

    Code:
    #include <stdio.h>
    #include <stdint.h>
    
    int main()
    {
    # if (UINTPTR_MAX == 0xFFFFFFFF)
    #    define LG_SIZEOF_PTR 4
    #  elif (UINTPTR_MAX == 0xFFFFFFFFFFFFFFFF)
    #    define LG_SIZEOF_PTR 8
    #else
    	#define LG_SIZEOF_PTR 0
    #  endif
    
    	int a = LG_SIZEOF_PTR;
    
    	printf("ptr : %i\n",  a);
    }
    This displays 4 when _WIN64 is not defined and 8 when _WIN64 is defined.

    The only change is that I've added the catch all final #else to set LG_SIZEOF_PTR to 0 if neither of the #if conditions are true.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.7.2)

  5. #5
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,465

    Re: Value of UINT64_MAX ?

    Thanks 2kaud - I found another version of stdint.h where this was defined:-
    Code:
    #define UINT64_MAX       0xffffffffffffffffULL
    So it looks like the different definitions are getting confused somehow. I'll have to leave it till tomorrow when I'm feeling a bit fresher !
    "A problem well stated is a problem half solved. - Charles F. Kettering

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,213

    Re: Value of UINT64_MAX ?

    I realise that the code in post #1 probably isn't yours - and you're just the one who has to get it to work with VS. But why do it like this? - why not just use sizeof(int*). This will give the number of bytes used for a pointer - and no messy comparison tests! This would even work for a 16-bit memory computer!

    Code:
    #define UINT64_MAX       0xffffffffffffffffULL
    #define UINT64_MAX       0xffffffffffffffffui64
    These should be same - as the first is unsigned long long (which should be unsigned 64 bit) and the second is unsigned integer 64 (which is unsigned 64 bit).
    Last edited by 2kaud; April 30th, 2018 at 02:21 PM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.7.2)

  7. #7
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,465

    Re: Value of UINT64_MAX ?

    The global property sheet (Microsoft.Cpp.x64.user.props) is referencing a #include folder belonging to mingw (so I'm picking up the wrong version of stdint.h)

    I need to edit my global properties to either remove that folder - or make sure it gets searched after the MSVC ones. Unfortunately, for the life of me I can't remember where to edit my global properties! I can bring up property sheets for an indiviual project - but I've totally forgotten how to edit the global properties...
    "A problem well stated is a problem half solved. - Charles F. Kettering

  8. #8
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,213

    Re: Value of UINT64_MAX ?

    Does this help. Its for VS2010, but it seems to be OK for VS2015.

    https://social.msdn.microsoft.com/Fo...orum=vcgeneral
    Last edited by 2kaud; May 1st, 2018 at 11:01 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.7.2)

  9. #9
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,465

    Re: Value of UINT64_MAX ?

    Hi 2kaud - I followed those instructions and managed to bring up the page for editing Microsoft.Cpp.x64.user.props (i.e. the global properties). It contains a VC++ Directories tab which lists $(VC_IncludePath). There's also the usual C++->General->Additional Include Directories. The problem here is that my additional #include directories are getting searched before the ones in VC++ Directories (whereas I need them to searched after).

    Here's the arrangement from VS2005 and you can see that it just had one window for everything. I could re-arrange the search order just by re-ordering the folders there. I guess I could try adding $(VC_IncludePath) to that 2nd window and see if that works...

    Name:  VC8-Options.jpg
Views: 28
Size:  36.8 KB
    Last edited by John E; May 3rd, 2018 at 03:36 AM.
    "A problem well stated is a problem half solved. - Charles F. Kettering

  10. #10
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,213

    Re: Value of UINT64_MAX ?

    What's the content of the PATH environment variable and INCLUDE from a VS command prompt?
    Last edited by 2kaud; May 3rd, 2018 at 03:53 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.7.2)

  11. #11
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,465

    Re: Value of UINT64_MAX ?

    INCLUDE looks like this:-
    Code:
    INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE;C:\Progra
    m Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE;C:\Program Files (x
    86)\Windows Kits\10\include\10.0.10240.0\ucrt;C:\Program Files (x86)\Windows Kit
    s\NETFXSDK\4.6.1\include\um;C:\Program Files (x86)\Windows Kits\8.1\include\\sha
    red;C:\Program Files (x86)\Windows Kits\8.1\include\\um;C:\Program Files (x86)\W
    indows Kits\8.1\include\\winrt;
    and PATH looks like this:-
    Code:
    Path=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExten
    sions\Microsoft\TestWindow;C:\Program Files (x86)\MSBuild\14.0\bin;C:\Program Fi
    les (x86)\Microsoft Visual Studio 14.0\Common7\IDE\;C:\Program Files (x86)\Micro
    soft Visual Studio 14.0\VC\BIN;C:\Program Files (x86)\Microsoft Visual Studio 14
    .0\Common7\Tools;C:\Windows\Microsoft.NET\Framework\v4.0.30319;C:\Program Files
    (x86)\Microsoft Visual Studio 14.0\VC\VCPackages;C:\Program Files (x86)\HTML Hel
    p Workshop;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Perfor
    mance Tools;C:\Program Files (x86)\Windows Kits\8.1\bin\x86;C:\Program Files (x8
    6)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\;C:\Program Files (x86)\N
    VIDIA Corporation\PhysX\Common;C:\Program Files\Common Files\Microsoft Shared\Wi
    ndows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\
    Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\Windows
    PowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Windows\system32\
    config\systemprofile\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Fi
    les\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Windows Kits\8.1
    \Windows Performance Toolkit\;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:
    \strawberry\perl\bin;C:\Python37;C:\Python37\scripts;C:\Program Files\Meson\;C:\
    Program Files (x86)\CMake\bin;C:\Program Files\TortoiseSVN\bin
    The good news is that adding $(VC_IncludePath) does seem to be working (see my previous post).
    "A problem well stated is a problem half solved. - Charles F. Kettering

  12. #12
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,213

    Re: Value of UINT64_MAX ?

    The good news is that adding $(VC_IncludePath) does seem to be working (see my previous post).
    Great!
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.7.2)

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)