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 8650097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:43:56+00:00 2026-06-12T13:43:56+00:00

Possible Duplicate: C integer overflow behaviour when assigning to larger-width integers I haven’t found

  • 0

Possible Duplicate:
C integer overflow behaviour when assigning to larger-width integers

I haven’t found a clear answer on this in my googling. Say you have two expressions:

int16_t a16 = 100;
int16_t b16 = 2000;
int16_t result16 = (a16 * b16) / a16;

int8_t a8 = 100;
int8_t b8 = 20;
int8_t result8 = (a8* b8) / a8;

When evaluation the expressions (a16 * b16) / a16 and (a8 * b8) / a8, are they always promoted to int during the evaluation and then the final result is converted back to the desired type (int16_t or int8_t) just before the assignment, or is this integer promotion entirely optional? Is integer promotion while evaluating an integer expression always done, or is it just simply allowed?

If it’s always done, then I can expect the two operations to not overflow (assuming int is 32-bits). If it’s only allowed to be done (and not required), then the operations may overflow. I’d like to know the behavior better.

  • 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-12T13:43:57+00:00Added an answer on June 12, 2026 at 1:43 pm
    int16_t result16 = (a16 * b16) / a16;
    int8_t result8 = (a8* b8) / a8;
    

    These declarations are the same as:

    int16_t result16 = (int16_t) ((int) a16 * (int) b16) / (int) a16);
    int8_t result8 = (int8_t) ((int) a8 * (int) b8) / (int) a8);
    

    The integer promotions are required by a conforming implementation. Some embedded compilers by default do not perform integer promotions to enhance code density (example: MPLAB C18 compiler) but these compilers usually also have an ANSI mode to be conforming.

    Now for C the behavior is described in terms of an abstract machine in which the issues of optimization are irrelevant. If the compiler can achieve the same observable behavior for the program without performing an integer promotion, it is free not to do it.

    Assuming your int is 32-bit, you are right, this expression: (a16 * b16) / a16 cannot overflow.

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

Sidebar

Related Questions

Possible Duplicate: Why does this integer division yield 0? I have a C header
Possible Duplicate: Best way to detect integer overflow in C/C++ If I have an
Possible Duplicate: Best way to detect integer overflow in C/C++ i have tried to
Possible Duplicate: Best way to detect integer overflow in C/C++ how do we check
Possible Duplicate: Integer summing blues, short += short problem I feel dumb that this
Possible Duplicate: Integer with leading zeroes I'm very new to Java. I did this
Possible Duplicate: php validate integer Currently I'm using this method: Validate the input using
Possible Duplicate: Best way to detect integer overflow in C/C++ What is the best
Possible Duplicate: Best way to detect integer overflow in C/C++ Oftentimes when I've coded
Possible Duplicate: Why can Integer and int be used interchangably? I am trying to

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.