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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:35:48+00:00 2026-06-07T02:35:48+00:00

According to this SO post: What is the size of an enum in C?

  • 0

According to this SO post:
What is the size of an enum in C?
enum types have signed int type.

I would like to convert an enum definition from signed int to unsigned int.

For example, on my platform an unsigned int is 32-bits wide.
I want to create an enum:

typedef enum hardware_register_e
{
    REGISTER_STATUS_BIT = (1U << 31U)
} My_Register_Bits_t;

My compiler is complaining that the above definition is out of range (which it is for a signed int).

How do I declare unsigned int enum values?

Edit 1:

  1. The preference is not to expand to 64 bits (because the code resides
    in an embedded system).
  2. Due to skill limitations, C++ is not allowed for this project. 🙁

Edit 2:

  • Compiler is IAR Embedded Workbench for ARM7.
  • 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-07T02:35:49+00:00Added an answer on June 7, 2026 at 2:35 am

    Unfortunately ISO C standard (c99 6.4.4.3) states that the enumeration constants are of type int. If you compile the above with e.g. gcc -W -std=c89 -pedantic, it will issue a warning ISO C restricts enumerator values to range of ‘int’ [-pedantic]. Some embedded compilers may not accept the code at all.

    If your compiler is of the pickier variety, you can workaround the issue by using

    typedef enum hardware_register_e
    {
        REGISTER_STATUS_BIT = -2147483648   /* 1<<31, for 32-bit two's complement integers */
    } hardware_register_t;
    

    but it works correctly only if int is 32-bit two’s complement type on your architecture. It is on all 32-bit and 64-bit architectures I have ever used or heard of.

    Edited to add: ARM7 uses 32-bit two’s complement int type, so the above should work fine. I only recommend you keep the comment explaining that the actual value is 1<<31. You never know if somebody ports the code, or uses another compiler. If the new compiler issues a warning, the comment on the same line should make it trivial to fix. Personally, I’d wrap the code in a conditional, perhaps

    typedef enum hardware_register_e
    {
    #ifdef __ICCARM__
        REGISTER_STATUS_BIT = -2147483648   /* 1<<31, for 32-bit two's complement integers */
    #else
        REGISTER_STATUS_BIT = 1 << 31
    #endif
    } hardware_register_t;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Android 2.3, so according to this post: Streaming Audio from A URL
It appears that glColorMaterial() is absent from OpenGL ES . According to this post
according to this post and from OpenCV documentation, I can initialize and access each
Possible Duplicate: Can we post on Google plus from android application? According to this
Now according to this post: Start a list from a certain number this has
According to this post , IDEA uses Osmorc to run OSGi frameworks. It, in
According to this post in Recursive Descent vs. LALR , any LALR(k) can be
According to this post , i ask $title. Which are your favorite PHP coding
According to this post on Daring Fireball a new iPhone SDK Agreement release in
According to this SO post: How to check the TEMPLATE_DEBUG flag in a django

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.