This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Alternate method of using "sfr" and "sbit" for Misra Compliance

I want to change my code along with Compiler library header files to have Misra-C Compliance.

For the following code, there is an Misra Violation saying that
"There shall be no definitions of objects or functions in a header file".
sfr P0 = 0x80;
sbit P0_7 = P0^7;

And " ANSI C error: 'expression must have a constant value' " for
sbit P0_7 = P0^7;

Please suggest an alternate method for implementing the above code?

Thank you.

Parents
  • "I want to change my code along with Compiler library header files to have Misra-C Compliance."

    You are, presumably, using some tool to check for "MISRA compliance", yes?

    Your problems are not so much with MISRA compliance itself, but rather with configuring the tool to understand the Keil extensions.

    "There shall be no definitions of objects or functions in a header file"
    sfr P0 = 0x80;
    sbit P0_7 = P0^7;

    These are not "definitions of objects" in the conventional sense; however, you could probably put them into a .c file instead, and change the header to:

    extern sfr  P0;
    extern sbit P0_7;
    

    "ANSI C error: 'expression must have a constant value'" for
    sbit P0_7 = P0^7;

    This is a pure Keil extension; it is not ANSI 'C' - the only way around this is to use a tool that supports this Keil-specific extension, and configure it correctly!

    You need to speak to your tool vendor, or perhaps try http://www.phaedsys.org/ or http://www.hitex.co.uk/

Reply
  • "I want to change my code along with Compiler library header files to have Misra-C Compliance."

    You are, presumably, using some tool to check for "MISRA compliance", yes?

    Your problems are not so much with MISRA compliance itself, but rather with configuring the tool to understand the Keil extensions.

    "There shall be no definitions of objects or functions in a header file"
    sfr P0 = 0x80;
    sbit P0_7 = P0^7;

    These are not "definitions of objects" in the conventional sense; however, you could probably put them into a .c file instead, and change the header to:

    extern sfr  P0;
    extern sbit P0_7;
    

    "ANSI C error: 'expression must have a constant value'" for
    sbit P0_7 = P0^7;

    This is a pure Keil extension; it is not ANSI 'C' - the only way around this is to use a tool that supports this Keil-specific extension, and configure it correctly!

    You need to speak to your tool vendor, or perhaps try http://www.phaedsys.org/ or http://www.hitex.co.uk/

Children