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

Username
  

Password
  





  The Meaning of Rule 12.6?
Posted by: Hammer - 06-04-2006, 07:30 AM - Forum: 6.12 Expressions - Replies (1)

I am trying to understand this rule and need someone to clarify its exact meaning.

which of the following are violations of Rule 12.6?

Code:
if((x==y)|(y==a))/*Violation?, could || have been meant?*/
   {    

   }
This is a violation of the old equivalent rule 36 but is it still a violation now?

Code:
a=a+y+x+(x||y);
/*Violation, effectively boolean expression used with + operator*/

Code:
int32_t x=5;
int32_t y=11;

if(x||y) /*Could this be a violation??? because x and y are not effectively boolean*/
   {
      
   }


Thanks for you help!

Print this item

  Rule 5.1
Posted by: quangp - 05-04-2006, 10:37 PM - Forum: 6.5 Identifiers - Replies (1)

Need clarification on rule 5.1 (equivalenet to rule 11 in MISRA C1):

Does this rule disallow to use identifier that has more than 31 characters? Even though the first 31 characters are guaranteed to be distinct.

Thanks,

quangp

Print this item

  implicitly cast
Posted by: warawut - 05-04-2006, 03:57 AM - Forum: General Questions - Replies (3)

According to source code below, please kindly help me to clear understanding whether where are the implicitly cast and they will cast to what type?

Warning: Unsuffixed integral literal implicitly cast to another type.


Source code
struct {
unsigned char multiple: 1;
unsigned char event: 1;
unsigned char checksum: 1;
unsigned char conditional: 1;
} flag;
...

void transmit(void)
{
…
if (flag.conditional == 1) { [color=red][b]

Print this item

  Rule 19.4
Posted by: aravind - 31-03-2006, 07:20 PM - Forum: 6.19 Preprocessing Directives - Replies (1)

Is the usage of ternary operator (? :) inside a C macro violation of rule 19.4. For e.g. the following function-like macro

#define abs(x) (((x) >= 0) ? (x) : -(x))

According to Rule 19.4 - C macros shall only expand to a braced initialiser, a constant, a parenthesized expression, a type qualifier, a storage class specifier or a do-while construct.

Does the above function-like macro conform to rule 19.4?

Print this item

  Integral promotion.
Posted by: warawut - 01-03-2006, 04:08 AM - Forum: General Questions - Replies (2)

I have some doubt about the integral promotion whether how integral promotion's rule perform with the unsuffixed constant (hexadecimal).
Example:

16bit ECU
0xffff -----> Will it promote to \"int\" or \"unsigned int\"?
0xffffffff -----> Will it promote to \"int\" or \"unsigned int\"?

32bit ECU
0xffff -----> Will it promote to \"int\" or \"unsigned int\"?
0xffffffff -----> Will it promote to \"int\" or \"unsigned int\"?

Who know how does it perform with hexadecimal.
Please kindly give me the answer.

Thanks in advance,
Warawut.

Print this item

  Rule 1.1 and Number of characters for Header File name
Posted by: lv - 21-02-2006, 05:12 PM - Forum: 6.1 Environment - Replies (1)

The rule 1.1 deals with limits defined in chapter 5.2.4 of ISO-9899:1990 norm.

But for the #include preprocessing directive, the 9899:1999 (and so, I suspect that the C90 is more restrictive) specify in chapter 6.10.2 some restriction (limits) about the sequence placed between the \" \" or < > delimiters:

The implementation shall provide unique mappings for sequences consisting of:
- one or more digits (no case sensitive)
- followed by a period
- followed by a single letter.
- The mapping is restricting to eight significant characters before the period.


So if the sequence between \" and < > delimiters is specified, then the header file names are impacted.

I would like to know if it is MISRA compliant to have a header file name with more than 8 characters before the period ?
(Example: FooComponent_Api.h)


Thanks in advance for your answer.

Print this item

  Rule 20.9
Posted by: Nuria - 21-02-2006, 10:56 AM - Forum: 6.20 Standard Libraries - Replies (1)

Rule 20.9 says that the input/output library shall not be used in production code.

We can not use the function open because is not ANSI C. Which would be the alternative to open a file instead of fopen?

Thanks.

Print this item

  Rule 2.1
Posted by: nikunj - 16-02-2006, 07:22 AM - Forum: 6.2 Language Extensions - Replies (4)

What are the possible scenarios in which Rule 2.1 will be violated?

Rule allows for Macros, C-functions and Assembly functions.

If any assembly code is used directly it will be reported as an compliler error for undefined identifier etc.

Print this item

  Is rule 10.5 compliant with rule 10.3?
Posted by: rmgalles - 07-02-2006, 07:53 PM - Forum: 6.10 Arithmetic Type Conversions - Replies (3)

Rule 10.3 requires a \"complex expression\" of integer type only be explicitly cast to a NARROWER type.

Rule 10.5 requires that bitwise operator RESULT be immediately cast to the underlying type (NOT a NARROWER type).

Based on the discussion in 6.10.5, a shift-expression IS considered a \"complex expression\" such that rule 10.3 should apply to rule 10.5? If so, doesn't this cast back to the underlying type violate rule 10.3?

The primary motivation of this question is that I think rule 10.3 should prohibit an explicit cast to a WIDER type, rather than only allow a cast to a NARROWER type. This seems to fit better with 6.10.3's discussion under \"evaluation type confusion\" (p. 38), as well as 6.10.1's \"to change the type in which subsequent arithmetic operation is performed\" statement.

It might be preferred that an expression use the implicit conversion rather than explicitly casting to the underlying type -- but should explicitly casting to the underlying type be prohibited by rule 10.3? Sometimes, the cast to the underlying type may be the same as the actual (promoted) type of the expression, and other times the cast to the underlying type is a conversion of the promoted type back to the underlying type. This depends on the types and the implementation-defined sizeof(int).

Some examples:

(1) Should:
[code]U16 = (uint16_t)((uint16_t)U8

Print this item

  Rule 19.12 (# and ## operator) real issue?
Posted by: rmgalles - 06-02-2006, 10:16 PM - Forum: 6.19 Preprocessing Directives - Replies (6)

I recognize that \"The order in which # and ## operations are evaluated during macro substitution (6.10.3.2, 6.10.3.3).\" [ISO C 9899:1999 J.1 Unspecified behavior] is UNSPECIFIED behavior.

However, what is the real issue with the order of evaluation being unspecified? I realize that rule 19.13 goes even further than MISRA-C:1998 and advises that these operators not even be used at all. However, I'm wondering if someone can provide an example where the order of evaluation matters?

The only example I can think of is:

Code:
#define MYMACRO(a,b) # a ## b
MYMACRO(foo,bar)

Could produce (## evaluated first, then #):
Code:
\"foobar\"

or (# evaluated first, then ##):
Code:
\"foo\" bar

depending on the order of evaluation.

However, as long as ONLY # operators, or ONLY ## operators are used (i.e., # and ## operators are not BOTH used in the SAME macro), then I don't see a problem.

It is sometimes useful to use these operators more than once within a macro, particularly the ## operator:

Code:
#define MY_IDENTIFIER(a) PRE_##a##_SUF
MY_IDENTIFIER(foo)

Will always result in a new identifier:
Code:
PRE_foo_SUF

It doesn't matter which ## operator executes first:
Code:
PRE_##foo##_SUF -> PRE_foo##_SUF -> PRE_foo_SUF
PRE_##foo##_SUF -> PRE_##foo_SUF -> PRE_foo_SUF

Both result in the proper final identifier.

Macros can then be used to replace otherwise \"copy-and-paste\" code with a single macro. Then, changes to the repetitive code can be made in a single location (the macro) rather than duplicated across several lines of code. This minimizes \"copy-and-paste\" errors in the original code creation, as well as \"copy-and-paste\" errors in code maintenance.

Granted, the use of such macros is not extremely common or widespread. However, it does have its practical uses, and when done may require more than one ## operator within a single macro.

I just wondered if a specific example is available that shows where the order of evaluation matters or could cause a problem based on the UNSPECIFIED behavior when only one TYPE of operator (# only, or ## only) is used in a macro, but the one operator may be used MORE THAN ONCE in the same macro.

If there is no such issue, could rule 19.12 be updated to:
\"Both # and ## operators shall not be used in the same macro definition.\"

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,173
» Latest member: SnakeLeon
» Forum threads: 998
» Forum posts: 2,752

Full Statistics

Online Users
There are currently 555 online users.
» 0 Member(s) | 552 Guest(s)
Applebot, Bing, Google

Latest Threads
Rule 6.2.1: non-inline co...
Forum: 4.6 Basic concepts
Last Post: cgpzs
22-11-2024, 10:11 AM
» Replies: 0
» Views: 43
Rule 0.1.2
Forum: 4.0 Language independent issues
Last Post: stephanmuench
21-11-2024, 01:12 PM
» Replies: 0
» Views: 55
A18-9-4
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
23-10-2024, 12:04 PM
» Replies: 2
» Views: 406
A8-4-5: are partial moves...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
22-10-2024, 02:03 PM
» Replies: 1
» Views: 343
model information blocks ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:27 PM
» Replies: 1
» Views: 4,463
MISRA AL SLSF - Rule 043I
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:11 PM
» Replies: 1
» Views: 8,878
MISRA AC EC guidelines
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:21 AM
» Replies: 4
» Views: 15,535
News on future releases
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:05 AM
» Replies: 1
» Views: 5,709
Signal naming convention ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 07:57 AM
» Replies: 1
» Views: 7,265
Rule 7.0.2: operator cons...
Forum: 4.7 Standard conversions
Last Post: karos
14-10-2024, 08:52 PM
» Replies: 2
» Views: 458