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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:58:31+00:00 2026-06-14T07:58:31+00:00

First off, this is similar to: How are integer types converted implicitly? but with

  • 0

First off, this is similar to: How are integer types converted implicitly? but with a different MISRA warning.

The compiler does not generate a MISRA error, but the static analysis tool does. I have a ticket with the tool manufacturer in progress.

Given:

#include <stdio.h>
enum Color {RED, VIOLET, BLUE, GREEN, YELLOW, ORANGE};

int main(void)
{
  enum Color my_color;
  my_color = BLUE;
  if (my_color == YELLOW)  // Generates MISRA violation, see below.
  {
     printf("Color is yellow.\n");
  }
  else
  {
     printf("Color is not yellow.\n");
  }
  return 0;
}

The static analysis tool is generating a MISRA violation for the if statement:

MISRA-2004 Rule 10.1 violation: implicitly changing the signedness of an expression.
Converting "4", with underlying type "char" (8 bits, signed),
to type "unsigned int" (32 bits, unsigned) with different signedness.

Is the compiler correct (not identifying the defect) or the static analysis tool?

  • 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-14T07:58:33+00:00Added an answer on June 14, 2026 at 7:58 am

    Per the C language specification, the type of the expression:

    typedef enum Colors {RED, VIOLET, BLUE, GREEN, YELLOW, ORANGE} Colors_t;  
    

    is a signed int.

    Also according the language, the value of an enumerated item is the smallest unit that can contain the entire enumeration. So in the above enumeration, BLUE has the type signed char.

    The static analysis tools are reporting a MISRA violation when a variable of Colors_t is compared to BLUE:

    Colors_t my_color;
    if (my_color == BLUE) // This generates a MISRA violation.
    

    The violation is signed int compared to signed char.

    Also, the enumeration items can be mixed with other enumeration types without error, since the enumerations are not a unique type:

    typedef enum Tree_Species {REDWOOD, CYPRUS, PALM, OAK, JUNIPER, SEGUARO} Tree_Species_t;
    Tree_Species_t my_tree;
    my_tree = BLUE;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, fairly new to JS but getting better :-) This question is similar
First off, this is NOT a duplicate of: Turn a C string with NULL
First off, my problem is quite similar to this one . I would like
First off, I know I can copy "this" on instantiation, but that doesn't work
First off this is in Microsoft Office 2010. I'm comparing two different worksheets each
First off, this is not a dupe of: Is it safe to cast an
First, I apologize if this has been answered. I've seen many similar questions but
First off, I know that there are similar questions on SO, but I have
First off, I'm a beginner in mobile development. I've seen many similar questions but
First off - apologies if this or a similar question has been asked before.

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.