Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7999911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:38:21+00:00 2026-06-04T15:38:21+00:00

Today i was trying some types defined in the cstdint header file: std::uint16_t ,

  • 0

Today i was trying some types defined in the cstdint header file:
std::uint16_t, std::uint_least16_t and so on..

I think they are very useful because you know exactly or at least how big they are, unlike the more common platform-specific ones: int, unsigned int, and so on..
But there is one problem that I think can cause many errors.

Let’s say we have this code:

#include <cstdint>
#include <iostream>

int main()
{
  std::uint_fast16_t test = 0;

  test = 65536;

  std::cout << test;

  return 0;
}

We know that std::uint_fast16_t should be AT LEAST 2 bytes.

If the uint_fast16_t is exactly 2 bytes, this code gives a warning because of the overflow. But in my case the uint_fast16_t is 8 bytes (checked it previously).

So in my case this code compiles and runs fine, in the other we get a warning. Our code isn’t portable.
This is just wrong for me.
Even if the variable can hold that data, the compiler should at least give us a warning or suggesting us to use a bigger type.
Am i right? Or did i misunderstand the purpose of those types?

I compiled the code using g++ with these flags

-Wall -Werror -pedantic -std=c++0x

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:38:23+00:00Added an answer on June 4, 2026 at 3:38 pm

    Compiler cannot provide any other warning, because those types are typedefs and they’re treated exactly as the types they’re synonyms to. That’s how C++ works. You have UINT_FAST16_MAX and possibly std::numeric_limits<std::uint_fast16_t>::max() to tell you the maximum value this type can hold. It’s your job to use that information.

    Also keep in mind most of types defined by stdint are actually optional, so just by using them and not checking if they’re exist you make your code unportable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to do some convention tests today, and getting all the types
Actually i had been practicing some of the java programs today(trying to learn it
today I am basically trying to create some JAVA code that moves an actor
I was trying to follow some instructions today, and it starts with the comment
I got an error today while trying to do some formatting to existing code.
I think I am hallucinating. I am trying to add some persistence to my
I was today trying to figure out on working with WebService and found many
I've search all over today trying to find how to do this, and not
I ran across the caret operator in python today and trying it out, I
I came across Side-by-side Assemblies for the first time today while trying to install

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.