MISRA Discussion Forums

Full Version: Definition of "object"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The word "object" is used in some rules of MISRA-C:2012. (e.g. Rule-8.9)
What is the definition of "object" in MISRA-C:2012?
Which of the following are considered as "object" in MISRA-C:2012?
  • Variable
  • Const-qualified variable
  • Function
  • Object-like macro
  • Function-like macro
First sentence here: https://en.wikipedia.org/wiki/Object_(computer_science)
Anything else would really surprise me:) - but let's wait for an official reply.
(This is not offical reply from MISRA)

"object" is defined in ISO-C. (MISRA C is a subset of ISO-C.)

object (ISO/IEC 9899 section 3.14):
region of data storage in the execution environment,
the contents of which can represent values (1)(2)


Mostlikely, "object" meanings RAM area which is assigned for a variable.

-- refs --
(1) ISO/IEC 9899: 1990,Programming languages ― C, ISO, 1990
(2) ISO/IEC 9899: 1990,Programming languages ― C, ISO, 1999
I accidentally posted the same replies...

Thank you for the comments.
So, according to the definition of "object", would they be regarded as an "object", or NOT an "object"?

Variable -> "object", because it's stored in RAM.
Const-qualified variable -> ?, depends on whether it's stored in ROM or RAM.
Function -> not "object", because it can't represent values.
Object-like macro -> not "object", because it's not stored in RAM.
Function-like macro -> not "object", because it's not stored in RAM.
.
.
The MISRA C:2012 guidelines uses the definition as the C99 standard. ( see section 3.14 and 6.2.1 ). Regarding your specific examples:
Code:
* Variable                    // object
   * Const-qualified variable    // object
   * Function                    // not an object
   * Object-like macro           // not an object, but may expand to an object
   * Function-like macro         // not an object, but may expand to an object
Most of the MISRA C:2012 guidelines, including rule 8.9 apply after macro expansion.
For example:
Code:
int x;                  // object
   int fn(int y);          // function
   #define MYMAC(Z) Z
   int MYMAC(r) = 3;       // expands to int r = 3; which is an object definition
   MYMAC(fn)(x);           // expands to fn(x); which is a function call