CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2019
    Posts
    59

    fixed width variables

    hi,
    can i use int8_t, int16_t, int32_t, int64_t, and uint8_t, uint16_t, uint32_t, uint64_t,to make sure the widths do not change from different versions of visual studio?. Like one version might handle unsigned int as 4 bytes and another version might handle it as 8 bytes.
    Last edited by @EE@; September 13th, 2022 at 01:00 AM.

  2. #2
    Join Date
    Aug 2019
    Posts
    59

    Re: question on structures

    any input?.

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,301

    Re: question on structures

    Victor Nijegorodov

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

    Re: question on structures

    can i use int8_t, int16_t, int32_t, int64_t, and uint8_t, uint16_t, uint32_t, uint64_t,to make sure the widths do not change from different versions of visual studio?
    Basically, yes. Note though that int8_t is usually treated as a type char (eg for std::cout). Also note that .size() and std::size() return type is size_t whose width does change depending upon whether compiling for 32 or 64 bit.

    Although it is unlikely that widths would change between versions of VS. Note though, that various MS specific types (defined in windows.h) that relate to pointers do change size depending upon whether compiling for 32 or 64 bit. In existing 32 bit code if any 32 bit variable is used to hold a memory address (typically DWORD) then this code will not be correct if compiled for 64 bit. Windows data types also include specific widths. See
    https://docs.microsoft.com/en-us/win...ows-data-types
    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++23 Compiler: Microsoft VS2022 (17.4.1)

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