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

  • Home
  • SEARCH
  • 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 4625512
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:16:59+00:00 2026-05-22T03:16:59+00:00

While attempting to read data from memory into an enum via the following code,

  • 0

While attempting to read data from memory into an enum via the following code, I got these weird results:

void read_memory (const unsigned, const unsigned, unsigned* const);

/* ... */

enum {DATA_0, DATA_1, DATA_2} data;
read_memory(base_addr, offset, &data);  //data = 0x0900
data >>= 8;  //data = 0x7e000000

I worked around this by introducing a temporary variable of unsigned type. But I’d like to be sure to understand why the previous method does not work.

First of all, I’m aware that the standard does not require a specific width for enum types, as long as all members can be represented. As a matter of fact, 6.7.2.2 states that:

Each enumerated type shall be compatible with char, a signed integer type, or an
unsigned integer type.

But since the raw data read from memory fits in a char, I think it should not be an issue.
Moreover, if I understand correctly, “compatible” means that you can use it as if it were of such a type. In particular, objects of enumerated type can be operands of bitwise shift operators.
I’m also aware that signedness may be a problem as we don’t know if enum are signed or not. But, as far as I can tell, 0x0900 does not appear to be signed.

So where does the problem lie ?

  • 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-22T03:17:00+00:00Added an answer on May 22, 2026 at 3:17 am

    After testing the code outside the debugger, it turned out that it behaved correctly and it was the information displayed by gdb that was inaccurate.

    In fact, analyzing the disassembled machine code revealed that it did not match C source line numbers. As a result, the epilogue of the function was thought (by gdb) to be part of the data >>= 8; instruction.
    This issue remains strange to me since I compiled and linked all source and object files with -g -O0.

    Perhaps a bug in the compiler…

    Edit: Actually it had nothing to do with gdb, it was the debug symbols emitted by the compiler that were erroneous.

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

Sidebar

Related Questions

I am attempting to read the results from a SQL query into a List(Of)
I have data stored in a SQL database that I'm attempting to read into
while attempting to run rake, I run into the following error: heroku rake db:migrate
While going through university and from following the development of SO, I've heard a
I previously have been reading NMEA data from a GPS via a serial port
I'm attempting to read the file.txt into java line by line and then when
I'm attempting to use an AsyncTask to read from a file at regular intervals.
I am attempting to parse html data from a website using BeautifulSoup for python.
While attempting to get an old svn dump of a project under git control,
Occasionally while attempting to save a Crystal Report that I'm working on in VS2008,

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.