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

Username
  

Password
  





  Examples in 6.5.3 do not match definition of a loop-counter
Posted by: drstaiger - 14-10-2013, 10:16 AM - Forum: 6.6 Statements (C++) - Replies (5)

A loop counter is defined as loop control variable that is, among other conditions,

Quote:© modified in expression

The examples for rule 6-5-3 state:
Code:
for (x = 0; modify(&x); ) // Non-compliant
{
}
for (x = 0; x < 10; )
{
  x = x * 2; // Non-compliant
}
But in both cases x is not a loop counter due to condition © being not satisfied (the expression is empty, no modification of x here), and thus the rule's text is not violated.
Should the examples be changed to contain a ++x in the expression?

Print this item

  11.3: How many 'levels' deep?
Posted by: gs - 04-10-2013, 07:50 PM - Forum: 8.11 Pointer type conversions - Replies (6)

While I am not entirely sure from the wording in the document, does this rule only concern itself with comparisons "one level deep"? For example, casting "cv1 type *" to "cv2 type *" is prohibited but "cv1a type * cv1b *" to "cv2a type * cv1b *" is allowed? Would this mean casting "cv1a type * cv1b *" to "cv2a type * cv2b *" is then prohibitted? [Presume each 'cv#' combination is unique.] While the text of the last two examples suggests the answer is "Yes", I'd like to double check.

Print this item

  Clarification of Exception for Rule 10.4
Posted by: rgamble - 26-09-2013, 08:24 PM - Forum: 8.10 The essential type model - Replies (2)

The first exception to rule 10.4 states:

Quote:The binary + and += operators may have one operand with essentially character type and the
other operand with an essentially signed or essentially unsigned type;

In the examples, the following is specified as being compliant per this exception, as expected:

Code:
cha += u8a

However, the following is later included in a list of examples that are non-compliant:

Code:
u8a += cha

How can the first one be compliant and the second one not be? Was the intention of the exception that the first operand have essentially character type and the second have signed or unsigned type? Or is the example incorrect?

Print this item

  MISRA C - Rule 12.12
Posted by: Akhil - 18-09-2013, 07:00 AM - Forum: 6.12 Expressions - Replies (2)

Just wanted to know if Line 3 in the following case is a violation for Rule 12.12 ...??

1. int i;
2. float f=2.1;
3. i=(int)f >>2; //Typecasting should actually take care of the bit implementation of floats

Also, If its a violation to Rule 12.12..Does that mean all typecasts (from float to any other type) should also be considered as violationg this rule..?

Print this item

  9.3 and {0}
Posted by: gs - 11-09-2013, 07:58 PM - Forum: 8.9 Initialization - Replies (3)

Would the following example be compliant with rule #9.3?

Code:
int a[3][2] = {0};

Print this item

  Rationale for 11.9 -- NULL constant
Posted by: stephen.parker - 09-09-2013, 10:45 AM - Forum: 8.11 Pointer type conversions - Replies (1)

Can anyone explain what the rationale is for this rule? I could think of several arguments for why you shouldn't use NULL, and should prefer a plain 0 (as is generally preferred in C++). This feels like a stylistic issue.

Thanks,
stephen

Print this item

  6.8.5 Initializers and POD
Posted by: martin.dowie - 04-09-2013, 07:36 AM - Forum: 6.8 Declarators (C++) - Replies (1)

Rule 8-5-1 (Required) "All variables shall have a defined value before they are used."

My reading of this rule leads me to the conclusion that "POD" classes are effectively not allowed, since any user-defined constructor provided to give initial values to non-static member data results in the class no longer being POD. Example:

[code]// Standard headers
#include
#include // std::is_pod

// User-defined structs...how many are POD?
struct Trivial_Ctor { int i; };
struct With_User_Defined_Ctor { int i; With_User_Defined_Ctor() { } };
struct With_Initialised_Member { int i; With_Initialised_Member() : i(0) { } };

int main()
{
std::cout

Print this item

  Definition of "used" for Rule 21.3
Posted by: rgamble - 03-09-2013, 04:08 PM - Forum: 8.21 Standard libraries - Replies (2)

The rule states, in part, "The identifiers calloc, malloc, realloc and free shall not be used" but does not define what constitutes a use. Is the following example (intended to be) a violation of Rule 21.3?

Code:
void *(*mymalloc)(size_t) = malloc;

Print this item

  Rule 17.4 - can I reference to an array, inside a struct?
Posted by: fpeelo - 23-08-2013, 05:38 PM - Forum: 6.17 Pointers and Arrays - Replies (6)

I want to define a list of actions in ROM, so it cannot get corrupted. An array of struct, in ROM, where each struct contains enough information to define what the MCU should do.

One of the actions is to read some info from an exernal device. So it needs to go into a buffer, and the buffer is obviously in RAM.

The problem I have is, how do I make a typedef for a struct, where one member of the struct is a reference to the buffer? I will need to use the buffer as an array, and referring to an array element by index is of course not allowed, if a pointer type is used for the array.

Code:
typedef s_SomeStruct
{
  uint8_t *buf;  /* not ok, because SomeStruct.buf[x] will not be compliant */
  size_t bufsize;
} TSomeStruct;
But I cannot find a way to use an array type. For function parameters, I could have foo(uint8_t buf[]) but it's not going to compile in a structure definition
Code:
typedef s_SomeStruct
{
  uint8_t buf[]; /* you wha'? */
  size_t bufsize;
} TSomeStruct;
Is there a known way around this, other than creating a deviation?

Thanks

Frank

Print this item

  MISRA C 2012 Exemplar Test Suite
Posted by: Shweta - 20-08-2013, 05:38 AM - Forum: MISRA C:2004 to MISRA C:2012 migration - Replies (1)

Is MISRA C 2012 Exemplar can be made available or in case its already available then please let us know?

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,171
» Latest member: stephanmuench
» Forum threads: 998
» Forum posts: 2,752

Full Statistics

Online Users
There are currently 352 online users.
» 0 Member(s) | 349 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: 26
Rule 0.1.2
Forum: 4.0 Language independent issues
Last Post: stephanmuench
21-11-2024, 01:12 PM
» Replies: 0
» Views: 36
A18-9-4
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
23-10-2024, 12:04 PM
» Replies: 2
» Views: 382
A8-4-5: are partial moves...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
22-10-2024, 02:03 PM
» Replies: 1
» Views: 329
model information blocks ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:27 PM
» Replies: 1
» Views: 4,446
MISRA AL SLSF - Rule 043I
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:11 PM
» Replies: 1
» Views: 8,863
MISRA AC EC guidelines
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:21 AM
» Replies: 4
» Views: 15,507
News on future releases
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:05 AM
» Replies: 1
» Views: 5,694
Signal naming convention ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 07:57 AM
» Replies: 1
» Views: 7,249
Rule 7.0.2: operator cons...
Forum: 4.7 Standard conversions
Last Post: karos
14-10-2024, 08:52 PM
» Replies: 2
» Views: 438