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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:19:04+00:00 2026-06-06T09:19:04+00:00

Similar to the question Bitshift and integer promotion? , I have a question about

  • 0

Similar to the question Bitshift and integer promotion?, I have a question about integer promotion when using left bitshifts.

unsigned int test(void)
{
  unsigned char value8;
  unsigned int result;

  value8 = 0x12;
  result = value8 << 8;
  return result;
}

In this case, will be the value8 first promote to unsiged int or is it implementation specific?

6.5.7 Bitwise shift operators … 3 Sematics …
The integer promotions are performed on each of the operands. The type of the result is
that of the promoted left operand. If the value of the right operand is negative or is
greater than or equal to the width of the promoted left operand, the behavior is undefined.

It says that the “The integer promotions are performed on each of the operands.”, but what is here the promotion rule?

I assume that it should be convert to int if lesser rank than int, but I can’t find it.

I ask this, as one compiler (Renesas nc30wa) doesn’t promote to int, so the result is always 0 for my sample.

On this platform, a char is 8 bit wide and int 16 bits.

  • 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-06T09:19:06+00:00Added an answer on June 6, 2026 at 9:19 am

    The phrase “the integer promotions” is a very specific thing, found in (for C99) section 6.3.1.1 Booleans, characters, and integers:

    If an int can represent all values of the original type, the value is converted to an int; otherwise, it is converted to an unsigned int. These are called the integer promotions. All other types are unchanged by the integer promotions.

    So assuming your unsigned char can be held in an int, it will be promoted to an int. On those rare platforms where unsigned char is as wide as an int, it will promote to an unsigned int.

    This is only changed slightly in C11:

    If an int can represent all values of the original type (as restricted by the width, for a bit-field), the value is converted to an int; otherwise, it is converted to an unsigned int. These are called the integer promotions. All other types are unchanged by the integer promotions.

    If a specific compiler doesn’t follow this behaviour, then it’s not really conforming. However, given that the compiler you listed is for embedded systems, it’s not really surprising.

    Many are built for specific purposes and conformance is not always high on the list of requirements. There may be compiler flags that will allow it to more closely conform to the standard.


    Looking at your particular environment, the M16C Series,R8C Family C Compiler Package V.5.45 C Compiler has, in section 2.1.4 nc30 Command Line Options, subsection f. Generated code modification options:

    -fextend_to_int, -fETI: Performs operation after extending char-type data to the int type. Extended according to ANSI standards.

    although I suspect -fansi is probably a better choice since it covers a few other things as well.

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

Sidebar

Related Questions

A similar question was asked here: PHP variable like $myvar-test is not valid? And
A similar question was asked about a year ago, and wasn't quite resolved, but
Similar question from last night, I don't have access to edit the source HTML
Similar question: Using Silverlight for an entire website? That question is over 2 years
Despite similar question was asked , I have differnet situation: My app consists mostly
In a similar question I asked how to distributed integers using weights. I'm curious
I have asked a similar question to this one already but I think it
A similar question was asked and answered about a year ago, but was either
So I similar question was asked about a year an half ago here: How
I have posted similar question previously, but this time I am providing some code

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.