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

Username
  

Password
  





  conversions with constant
Posted by: natapush - 17-11-2005, 02:05 PM - Forum: 6.10 Arithmetic Type Conversions - Replies (1)

why are the following expressions are compliant/not compliant

u8a = 5U - compliant(u8a=u16b - not compliant at the same time)
u8a = 5UL not compliant

it is not a conversion to a wider integer type of the same signedness as in 10.1 a)
It is more an implicit conversion from wider to narrower types.
And why in one case it is compliant, and in another one not compliant.

Print this item

  16-bit and 32-bit compatibility
Posted by: natapush - 17-11-2005, 02:01 PM - Forum: 6.10 Arithmetic Type Conversions - Replies (1)

1.The expression

u16a = u16b + u16c yields a u16 bit result if int is 16 bits, this means that
u16a = u16b + u16c is compliant on a 16-bit machine.

but
u16a = u16b + u16c yields a signed 32 bit result on a 32-bit machine, so explicit type case has to be used to make the result compliant?
u16a =(u16)(u16b + u16c )

but this is not MISRA comform(rule 10.3 says type has to be narrower as the underlying type)

what is the solution for the expression u16a = u16b + u16c to be MISRA -conform on both machines?(will u16a = (u16)u16b + (u16)u16c also result in integral promotion?)

2. int16_t foo1(uint8_t x)
{
return(20000) compliant on the 16 bit machine
return(20000) not compliant on the 32 bit machine
}

right? (this is from example to rules 10.1-10.2 return(20000))

Print this item

  Rule 19.4, does order of #definition matter?
Posted by: gs - 11-11-2005, 07:23 PM - Forum: 6.19 Preprocessing Directives - Replies (1)

The MISRA II documentation states the following is compliant with the requirements of rule 19.4:

#define A 8
#define B A

However, it does not specifiy whether the following is also compliant:

#define B A
#define A 8

In the latter case, B does ultimately expand to 8, a constant, adhering to rule 19.4. However, at the time of #definition, B does not expand to a constant, braced initializer, parenthesized expression, type qualifier, storage class specifier or do-while-zero construct. Only after processing the #definition for A, is compliance certain (future re-#definition notwithstanding). My question: at what code processing point, does MISRA II, Rul 19.4, require the macro to evaluate to the prescribed formats? At the end of all preprocessing? At #definition time? Sometime else?

Print this item

  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

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,117
» Latest member: maheshthodimdala
» Forum threads: 966
» Forum posts: 2,655

Full Statistics

Online Users
There are currently 113 online users.
» 0 Member(s) | 111 Guest(s)
Bing, Google

Latest Threads
cvalue and constant integ...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
5 hours ago
» Replies: 1
» Views: 139
Rule 6-2-3 and C++17 [[fa...
Forum: 6.6 Statements (C++)
Last Post: misra cpp
5 hours ago
» Replies: 1
» Views: 111
10.2.3 Amplification
Forum: 4.10 Declarations
Last Post: misra cpp
12-04-2024, 02:20 PM
» Replies: 1
» Views: 122
Rule 7.0.5 Example potent...
Forum: 4.7 Standard conversions
Last Post: misra cpp
12-04-2024, 01:54 PM
» Replies: 1
» Views: 111
Rule 0.2.4 non-compliant ...
Forum: 4.0 Language independent issues
Last Post: misra cpp
12-04-2024, 01:51 PM
» Replies: 1
» Views: 141
Further guidance on MISRA...
Forum: 8.10 The essential type model
Last Post: mshawa
09-04-2024, 02:29 PM
» Replies: 0
» Views: 49
MISRA AC SLSF:2023 AMD1
Forum: MISRA AC resources
Last Post: david ward
05-04-2024, 01:56 PM
» Replies: 0
» Views: 71
MISRA AC GMG:2023 release...
Forum: MISRA AC GMG discussions
Last Post: misra-ac
25-03-2024, 06:01 PM
» Replies: 2
» Views: 414
14.3 and enum constants i...
Forum: 8.14 Control statement expressions
Last Post: misra-c
24-03-2024, 01:08 PM
» Replies: 1
» Views: 321
0-1-8. Exception: empty i...
Forum: 6.0 Language independent issues (C++)
Last Post: vmuthusu
18-03-2024, 04:01 AM
» Replies: 3
» Views: 8,320