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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:10:45+00:00 2026-05-16T22:10:45+00:00

I understand typecasting…but only in retrospect. My process to figure out what requires typecasting

  • 0

I understand typecasting…but only in retrospect. My process to figure out what requires typecasting in expressions is usually retroactive because I can’t predict when it will be required because I don’t know how the compiler steps through them. A somewhat trite example:

int8_t x = -50;
uint16_t y = 50;
int32_t z = x * y;

On my 8-bit processor (Freescale HCS08) sets z to 63036 (2^16 – 50^2). I can see how that would be one possible answer (out of maybe 4 others), but I would not have guessed it would be the one.

A better way to ask might be: when types interact with operators (+-*/), what happens?

  • 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-05-16T22:10:46+00:00Added an answer on May 16, 2026 at 10:10 pm

    The folks here that say that values are always converted to the larger type are wrong. We cannot talk about anything if we don’t know your platform (I see you have provided some information now). Some examples

    int = 32bits, uint16_t = unsigned short, int8_t = signed char

    This results in value -2500 because both operands are converted to int, and the operation is carried out signed and the signed result is written to an int32_t.

    int = 16bits, uint16_t = unsigned int, int8_t = signed char

    This results in value 63036 because the int8_t operand is first converted to unsinged int, resulting in 65536-50. It is then multiplied with it, resulting in 3 274 300 % 65536 (unsigned is modulo arithmetic) which is 63036. That result is then written to int32_t.

    Notice that the minimum int bit-size is 16 bits. So on your 8-bit platform, this second scenario is what likely happens.


    I’m not going to try and explain the rules here because it doesn’t make sense to me to repeat what is written in the Standard / Draft (which is freely available) in great detail and which is usually easily understandable.

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

Sidebar

Related Questions

I understand what System.WeakReference does, but what I can't seem to grasp is a
I understand that this has to be done with jQuery.noConflict() , but I can't
I understand how I can change the dns settings for my domains by editing
I understand these are necessary...of course to write proper code, but is there a
I understand how to use it, but the syntax of it bothers me. What
I understand the reason i should use retain , but why should I ever
I understand that there is a *.className selector since there can be multiple html
I understand what read and write do when used as a properties but I'm
I understand that the CLR needs to do marshaling in some cases, but let's
I understand that to add a path to $LOAD_PATH just do $LOAD_PATH.unshift(path) But I

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.