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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:17:12+00:00 2026-06-01T02:17:12+00:00

I have an odd problem when using the return result of a function and

  • 0

I have an odd problem when using the return result of a function and the += operator. The function is very simple, one line that fetches a unsigned char value from an array. When I use the = operator to place it into a variable, the value comes out correct. However, using the +=, the value comes out to be garbage.

Here is my code:

unsigned short value = 0;

value = this->memory->get(address) << 8; //this will work
value += this->memory->get(address) << 8; //this will set it to 52480 every time

unsigned char Memory::get(unsigned int address)
{
    return this->memory[address];
}

I figured that initializing value to zero would solve the problem; however, it does not. Also, casting the return to unsigned short still does not solve it.

  • 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-01T02:17:13+00:00Added an answer on June 1, 2026 at 2:17 am

    An unsigned char is not big enough to be shifted 8 bits on virtually every platform. This is undefined behaviour, to shift larger than the byte size.

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

Sidebar

Related Questions

I'm using Django's message framework, and I have a very odd problem where my
I have an odd problem...I'm using a documentation generator which generates a lot of
I have the odd problem that I am not able to open the properties
I have an odd problem with Django. I have a set of objects that
I have an extremely odd problem in my JUnit tests that I just can't
I have an odd problem with captureStillImageAsynchronouslyFromConnection. If I save the image using jpegStillImageNSDataRepresentation
I have an odd problem. I am using an AQGridView which has a method
This is an odd problem. I have a client object that I am building
I have a really odd issue... I am using the to.weekly and to.period function
I have a very odd issue trying to run this quite simple C program

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.