Definition of "object"

Moderators: misra-c, david ward

Post Reply
mz99
Posts: 5
Joined: Fri Feb 01, 2019 5:58 am
Company: .

Definition of "object"

Post by mz99 » Wed Apr 17, 2019 1:21 am

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

dg1980
Posts: 108
Joined: Wed Apr 27, 2016 2:33 pm
Company: Elektrobit Automotive GmbH

Re: Definition of "object"

Post by dg1980 » Wed Apr 17, 2019 6:05 am

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.

twakita
Posts: 1
Joined: Mon Aug 29, 2016 4:15 am
Company: Yazaki Corp

Re: Definition of "object"

Post by twakita » Tue Apr 23, 2019 2:49 am

(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

mz99
Posts: 5
Joined: Fri Feb 01, 2019 5:58 am
Company: .

Re: Definition of "object"

Post by mz99 » Fri Apr 26, 2019 9:05 am

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.
Last edited by mz99 on Fri Apr 26, 2019 9:34 am, edited 1 time in total.

mz99
Posts: 5
Joined: Fri Feb 01, 2019 5:58 am
Company: .

Re: Definition of "object"

Post by mz99 » Fri Apr 26, 2019 9:06 am

.
Last edited by mz99 on Fri Apr 26, 2019 9:28 am, edited 1 time in total.

mz99
Posts: 5
Joined: Fri Feb 01, 2019 5:58 am
Company: .

Re: Definition of "object"

Post by mz99 » Fri Apr 26, 2019 9:06 am

.

misra-c
Posts: 554
Joined: Thu Jan 05, 2006 1:11 pm

Re: Definition of "object"

Post by misra-c » Thu May 02, 2019 9:39 am

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: Select all

   * 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: Select all

   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
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.8 Declarations and defnitions”