Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





  Arithmetic on Pointers are MISRA compliant ?
Posted by: lv - 31-10-2005, 04:35 PM - Forum: 6.17 Pointers and Arrays - Replies (1)

The rules 17.1 to 17.3 give some possibilities to manipulate pointers (arithmetic, substraction, comparison) whereas the rule 17.4 doesn't authorize pointer manipulation in any way other than array indexing.

Should it be possible to explain me where I make a mistake in my understanding?

In particular, I would like to know if the following code is MISRA 2004 compliant concerning pointer manipulation:

Code:
    unsigned int tab[10];
    void test(void)
    {
        unsigned int *ptr;

        ptr = &tab[2];
        *ptr = 33;
        ptr++;                         /*  MISRA Compliant ? */
        *ptr = 11;
    }

I thank you in advance.

Best regards.

Print this item

  Rule 10.5 (required) and use of <<=
Posted by: Achim Olaf Zacher - 19-09-2005, 02:47 PM - Forum: 6.10 Arithmetic Type Conversions - Replies (1)

Rule 10.5: result of ~ and

Print this item

  Rationale for no goto, continue but allow break
Posted by: niall - 14-09-2005, 02:55 PM - Forum: 6.14 Control Flow - Replies (3)

I know this should have been brought up before, but in reviewing MISRA-2 this passed me by.
Being pedantic, why has the rule on break (14.6) been relaxed and not 14.5 (or 14.4)?
A break in a loop is just a goto!
I have no problem with it, it just smacks of inconsistency.

Print this item

  Examples
Posted by: MISRA Reply - 09-09-2005, 02:21 PM - Forum: 6.19 Preprocessing Directives - No Replies

Code:
#define M1 ;

This macro breaks rule 19.4. Macro expanding to Null statement is not allowed/

Code:
#define M2
#define M3 /* comment */

This macro expands to no body, and is therefore not prohibited by 19.4.

A comment in a macro definition is removed by the pre-processor. Rule 14.3 applied before
Pre-processing. Treatment of M2 and M3 is identical.

Code:
M1

Since definition of M1 macro was invalid, its use is already a violation.

Code:
M2;
M3;

After pre-processing, these are both Null statements. Before pre-processing, there are characters before the Null statement. This is not allowed by 14.3.

Print this item

  What is the essential requirement of Rule 13.3 ?
Posted by: Gavin McCall - 09-09-2005, 01:39 PM - Forum: 6.13 Control Statement Expressions - No Replies

Question: What is the essential requirement of Rule 13.3 ?

Rule 13.3 only prohibits the use of == and !=.

Does this mean that it is legitimate to use the >= and 10.0f ) /* compliant */
…
if ( speed = (10.0f – tolerance)) && ( speed

Print this item

  What is the character set referred to in Rule 3.2?
Posted by: Gavin McCall - 09-09-2005, 01:37 PM - Forum: 6.3 Documentation - Replies (1)

Question: What is the character set referred to in Rule 3.2?

Answer: MISRA C Steering Team

There are two character sets.
The source code is written in one character set.
The program can execute with input/output in a second character set.
These may or may not be the same.
Both the basic source character set and the basic execution character sets shall be documented.
This rule allows free choice of character sets for coding and execution. This use shall be documented.

Print this item

  Is Rule 20.1 applicable to \"defined\"?
Posted by: Gavin McCall - 09-09-2005, 01:30 PM - Forum: 6.20 Standard Libraries - No Replies

Question: Is Rule 20.1 applicable to \"defined\"?

(a) We presume that \"#define defined (10)\" will be in violation of Rule 20.1.

(b) If our presumption is correct, then which of \"reserved identifier\", \" macro\" or \"function\" will \"defined\" be?
We could not find the answer in ISO/IEC 9899:1990. Is it described somewhere in COR1, COR2 or AMD1?

Answer: MISRA C Steering Team 7/9/2005

(a) YES - defined is included in the text under the rule.

(b) defined is listed under 6.8.8 Predefined Macro Names.
It is also listed in Appendix G: Undefined Behaviour 54.

Print this item

  What about keywords?
Posted by: Gavin McCall - 09-09-2005, 01:04 PM - Forum: 6.20 Standard Libraries - No Replies

Question:

Is it correct to think that a keyword is out of the scope of Rule 20.1?

For example, \"#define int (10)\" violates Rule 19.4, doesn't it?

Answer: MISRA C Steering Team 7/9/2005

Keywords (as defined in 6.1.1) shall be considered to be in the scope of 20.1.
This is detailed in the supporting text and will be clarified in the Technical Corrigendum.

#define int (10)

This is not a violation of 19.4.

19.4 is concerned with the replacement text of a macro, and not its name.

Print this item

  Clarification of 20.1 - Intrepretation of \"not to be d
Posted by: Gavin McCall - 09-09-2005, 01:00 PM - Forum: 6.20 Standard Libraries - No Replies

Question 2: Interpretation of \"not be defined, redefined\"

a) Does it mean that \"#define\" is not allowed?

b) Is it not allowed to define as an object or a function, either?

Answer: MISRA C Steering Team clarification 7/9/2005

(a) YES - To define an object or a function with the name of a reserved identifier is prohibited under rule 20.2.

(b) YES - To #define macros with the name of a reserved identifier is prohibited.

Print this item

  Clarification of 20.1 Scope
Posted by: Gavin McCall - 09-09-2005, 12:57 PM - Forum: 6.20 Standard Libraries - No Replies

Question:

Question 1: Interpretation of \"Reserved identifiers, macros and functions in the standard library\"

Does this phrase mean
a) \"Reserved identifiers
AND
macros in the standard library
AND
functions in the standard library\"
or
b) \"Reserved identifiers in the standard library
AND
macros in the standard library
AND
functions in the standard library\" ?

It seems that in case of a) above, \"#define __ABC (10)\" violates Rule 20.1 whereas it does not in case of b), because \"__ABC\", which is a reserved identifier, is not in the standard library. Moreover, it is not guaranteed that all of \"__LINE__, __FILE__, __DATE__, __TIME__, __STDC__ \"
are in the standard library. If not in the standard library, it is presumed that they can be \"defined, redefined or undefined\". Which interpretation should we take, a) or b) ?

MISRA C Steering Team Answer (7/9/2005)
Option A.
Reserved identifiers are defined by ISO/IEC 9899:1990 sections 7.1.3 Reserved Identifiers, 7.13 Future library directions and 6.8.8 Predefined Macro Names.
Macros in the standard library are examples of reserved identifiers.
Functions in the standard library are examples of reserved identifiers.

Any identifier in the standard library is an example of reserved identifiers
.

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,207
» Latest member: [email protected]
» Forum threads: 1,017
» Forum posts: 2,800

Full Statistics

Online Users
There are currently 139 online users.
» 0 Member(s) | 136 Guest(s)
Bing, Google, UptimeRobot

Latest Threads
About MISRA-C 2023 Permit
Forum: General Questions
Last Post: misra-c
08-05-2025, 08:37 AM
» Replies: 1
» Views: 855
MISRA 2023 Test Suite
Forum: General Questions
Last Post: misra-c
08-05-2025, 08:35 AM
» Replies: 1
» Views: 817
Roadmap to c23 support
Forum: General Questions
Last Post: misra-c
08-05-2025, 08:34 AM
» Replies: 1
» Views: 240
Typo in Appendix C of MIS...
Forum: 8.10 The essential type model
Last Post: misra-c
08-05-2025, 08:21 AM
» Replies: 1
» Views: 207
Rule 7.0.5, example non-c...
Forum: 4.7 Standard conversions
Last Post: cgpzs
17-04-2025, 12:10 PM
» Replies: 0
» Views: 204
A3-3-2 Contradictory exam...
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
31-03-2025, 09:30 AM
» Replies: 2
» Views: 340
16.6.1 clarification
Forum: 4.16 Overloading
Last Post: cgpzs
31-03-2025, 09:29 AM
» Replies: 2
» Views: 324
Rule 9.3.1 - iteration st...
Forum: 4.9 Statements
Last Post: misra cpp
28-03-2025, 01:17 PM
» Replies: 1
» Views: 209
Rule 8.2.8 - why aren't a...
Forum: 4.8 Expressions
Last Post: misra cpp
28-03-2025, 01:05 PM
» Replies: 1
» Views: 232
Adopted modal expressions...
Forum: General Questions
Last Post: Yordan Naydenov
17-03-2025, 09:01 AM
» Replies: 0
» Views: 321