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

Username
  

Password
  





  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

  macro contains unaceptable items misra c 2004 19.4
Posted by: manojkdi - 31-07-2013, 11:35 AM - Forum: 6.19 Preprocessing Directives - Replies (1)

Example

#define MACRO_2 1(this macro is defined in some other file)

#define MACRO_1 MACRO_2

this statement is causing the warning in "macro contains unacceptable items misra c 2004 19.4".Is this warning valid? Is it really a invalid macro definition?

Print this item

  1-bit bitfield in boolean expression
Posted by: holger_l - 22-07-2013, 08:53 AM - Forum: 6.13 Control Statement Expressions - Replies (2)

Hi,
rule 13.2 makes an example how boolean data could be used in an expression:

Code:
if ( y ) /* Not compliant, unless y is effectively Boolean data (e.g. a flag) */
The example refers to a Boolean-by-enforcement type referred to in the appendix.
But what is with a 1-bit Bitfield? Is it a Boolean-by-construct?
Code:
struct { unsigned int flag1: 1, flag2: 1;} var;
...
if (var.flag1)                   /* violation of rule 13.2 ? */
if (( var.flag1) && (var.flag2)) /* violation of rule 12.6 ? */
if ((!var.flag1) && (var.flag2)) /* 2x violation of rule 12.6 ? */
if ((var.flag1 == 0) && (var.flag2 != 0)) /* OK, but clumsy and harder to read */
Thanks for a comment!

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,309
» Latest member: 1fuhd
» Forum threads: 1,066
» Forum posts: 2,933

Full Statistics

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

Latest Threads
13.2 Was TC2 correctly ap...
Forum: 8.13 Side effects
Last Post: misra-c
08-10-2026, 12:47 PM
» Replies: 1
» Views: 625
20.12 Does the stringific...
Forum: 8.20 Preprocessing directives
Last Post: misra-c
08-10-2026, 12:40 PM
» Replies: 1
» Views: 554
13.3 Should side effects ...
Forum: 8.13 Side effects
Last Post: misra-c
08-10-2026, 12:37 PM
» Replies: 1
» Views: 428
11.6 pointer to pointer t...
Forum: 8.11 Pointer type conversions
Last Post: misra-c
08-10-2026, 12:21 PM
» Replies: 2
» Views: 1,032
What is the UTLR of -1?
Forum: 8.10 The essential type model
Last Post: misra-c
08-10-2026, 12:15 PM
» Replies: 1
» Views: 597
10.3 Clarify if narrower ...
Forum: 8.10 The essential type model
Last Post: misra-c
08-10-2026, 11:57 AM
» Replies: 1
» Views: 508
It 8.12 intended to be so...
Forum: 8.8 Declarations and defnitions
Last Post: misra-c
08-10-2026, 11:50 AM
» Replies: 1
» Views: 455
Rule 0.1.1 Example f4
Forum: 4.0 Language independent issues
Last Post: cgpzs
07-10-2026, 11:07 AM
» Replies: 3
» Views: 726
Rule 6-2-2 Usage of std::...
Forum: 6.6 Statements (C++)
Last Post: misra cpp
25-09-2026, 05:43 PM
» Replies: 1
» Views: 437
M5-0-4 switch over unscop...
Forum: 6.5 Expressions (C++)
Last Post: misra cpp
25-09-2026, 01:00 PM
» Replies: 3
» Views: 539