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

Username
  

Password
  





  Rule 10.6: \"u\" Suffix to all unsigned constants
Posted by: Manni - 26-06-2006, 08:43 AM - Forum: 6.10 Arithmetic Type Conversions - Replies (5)

Hello

I have a disagreement with a supporter of a bigger MISRA-C:2004 rule checking tool.

He means, that the following is MISRA-C:2004 compliant :

Code:
void foo(UINT b)
{
UINT a;

a = b + 30;
}

I mean, it is not compliant . There must be \"u\"-Suffix:
Code:
void foo(UINT b)
{
UINT a;

a = b + 30[b]u[/b];
}

1. reason:
\"Rule 10.6 (required): A \"U\" suffix shall be applied to all constants of unsigned type.\"

I think, it is a clear case, when I read this rule. There is spoken from \"all\" constants of unsigned Type. So why there should be no \"u\" Suffix?




2. reason:

In \"Rule 10.1 (required):\" in MISRA-C:2004, are examples for this:

MISRA-C:2004 in Rule 10.1/10.2
Code:
... u8a + 5 /* not compliant */

... u8a + 5U /* compliant */



For me it is really a clear case, there must be a \"u\" suffix at the constant. But we need to clarify it, with an official answer for this tiny problem.

Thanks

Print this item

  question to examples of rule 6.12.2
Posted by: Manni - 23-06-2006, 01:30 PM - Forum: 6.12 Expressions - Replies (2)

Hi

In Rule 12.2

Quote:nested assignment statements
Assignments nested within expressions cause additional side effects. The best way to avoid any chance of this leading to a dependence on order of evaluation is to not embed assignments within expressions.

For example, the following is not recommended:
x = y = y = z / 3 ;
x = y = y++;

I don't understand, what could go wrong here:
1. x = y = y = z / 3 ;
2. x = y = y++;

If x = 1, y = 2, z = 3, I would say,

- for 1. the result for x is everytime 1
- for 2. the result for x is everytime 3

What could a compiler make different here?

thanks

Print this item

  Enumeration specifiers
Posted by: fwamolina - 20-06-2006, 05:25 PM - Forum: 6.10 Arithmetic Type Conversions - Replies (1)

My question is if the code bellow is not compliance with misrac-2004

uint16_t GetSpeed (void);
void IncreaseSpeed (void);
void DecreaseSpeed (void);
void GoodSpeed (void);

enum tagSPEED
{
Low,
Medium,
High
};

void main (void)
{
uint16_t uSpeed;

uSpeed = GetSpeed();

switch (uSpeed)
{
case Low:
IncreaseSpeed();
break;

case Medium:
GoodSpeed (void);
break;

case High:
DecreaseSpeed (void);
break;

default:
break;
}
}

Is there any solution for this case?


Normative reference:
Ansi-Iso-9899-1990 (6.5.2.2)
Misra-c2004 (6.10.3)

Print this item

  Pointer to void
Posted by: fwamolina - 14-06-2006, 02:36 PM - Forum: 6.11 Pointer Type Conversions - Replies (2)

I just want to know when a cast shall be performed between a pointer to void and any type or vice versa?

for example is this code compliance with misra-c?

void* GetNewObject (void);
void SetProperty (void*, uint8_t);

void main (void)
{
void* lpVoid;
OBJECT_T* lpObject;

lpVoid = NULL;
lpObject = NULL;

lpObject = GetNewObject ();
/* there is an explicit cast in
this function from OBJECT_T*
type to void* type, so GetNewObject
return an OBJECT_T* qualifier type */

lpVoid = lpObject;

SetProperty (lpVoid, 4U);

lpObject = lpVoid;

if (lpObject == lpVoid)
{
SetProperty (lpObject, 5U);
}

lpVoid = lpObject;
}

Print this item

  Implicit type convertion
Posted by: fwamolina - 05-06-2006, 09:08 PM - Forum: 6.10 Arithmetic Type Conversions - Replies (3)

My question is why my code test program (lint) generate an error when read this line.

U16 u16value;
U8 u8value;

u16value = (U16) u8value / 10U;

I think that line is absolutly compliance with misrac.

but in other hand this other line does not generate an error, but i think that it is not misra compliance.

U16 u16value;
U8 u8value;

u8value = (U16) u8value / (U16)10U;

Print this item

  Misra C:2004 Rule 12.12
Posted by: Hammer - 30-05-2006, 08:36 AM - Forum: 6.12 Expressions - Replies (3)

I would like to know how to represent a Violation of rule 12.12.
It is stated in C90 that bitwise operands are required to of integer type. Therefore bitwise operators can't be used with floats to demonstrate this rule as this would be a direct violation of rule 1.1.

Is maybe pointer indirection using an unsigned char the answer?

or are there implementations that allow bitwise operators to be used with floats?

Thanks for your help!

Print this item

  Rule 21.1: uint8 = ~uint8?
Posted by: Manni - 17-05-2006, 10:06 AM - Forum: 6.21 Run-time Failures - Replies (1)

Hello,

I use a tool, which tested code to MISRA-C:2004 compliance.

Here is a code example, on which our analyse tool says, there is a breach of rule 21.1.

Code:
...
...
int main(void)
{
...
...
    uint8_t STATE;
    uint8_t MASK;
...
...
    STATE = 0x01;
    MASK = 0x10;
...
...
    

    STATE = ~MASK;
        /* That line it is, which show up the breach of the rule*/

}

The Tool says, this breaches rule 21.1. But i think it's ok, or what do the MISRA comitee says?

thanks a lot

Print this item

  18.4 unions shall not be used
Posted by: Manni - 16-05-2006, 12:31 PM - Forum: 6.18 Structures and Unions - Replies (1)

Hello

I use unions in the following example. And I want to know, if in such a situation the use of unions is compliant or not compliant to MISRA-C:2004. Or if somebody has a better idea for a good implementation.


Code:
Example_Ports.h /* eg. a processor library of a processor manufacturer */
-----------FILE START----------------
...
...
...
#define PORTA        (*((volatile uint8_t *)(2000)))
/* So with \"PORTA\" we get access to data content of PORTA (adress 2000), it is a unsigned char, 8 bits. The file and this line is given by the processor manufacturer */
...
...
-----------FILE END----------------





/*Example_Test.c /* the example c file*/
-----------FILE START----------------
...
...
...

typedef union {
  uint8_t cb ;
  struct bits {
    uint8_t
    b0 : 1,
    b1 : 1,
    b2 : 1,
    b3 : 1,
    b4 : 1,
    b5 : 1,
    b6 : 1,
    b7 : 1 ;
} b ;
}example_bitfield;


#define B7       b.b7
#define B6       b.b6
#define B5       b.b5
#define B4       b.b4
#define B3       b.b3
#define B2       b.b2
#define B1       b.b1
#define B0       b.b0


    #define bitf_porta  (*((volatile example_bitfield*) &PORTA))
    /* Typcast to easy and safty access to each bit, see next line */


    #define porta_light bitf_porta.B5
    /* for a good identifier for the bit. which is for example for a light */


int main(void)
{
    uint8_t x;
    x = 0;

/* Now we can easy use the bits of the ports of the processor manufacturer. eg: */

        porta_light = 1;
        x = porta_light;

}

A. What do you think of this little example. Good user, or bad work?

B. Compliant to rule 18.4, a situation in which unions could be used? Or not. And then, how we could do it in a MISRA-C:2004 way?

thanks a lot

Best regards,
Manni

BTW: Big thanks for your help in my last threads. My MISRA Guide proceed.

Print this item

  19.7 no function-like macros
Posted by: Manni - 25-04-2006, 08:58 AM - Forum: 6.19 Preprocessing Directives - Replies (1)

Hi

Two questions about this rule:

1. Have somebody examples short for function-like macros?
2. When is a macro funktion-like?

best regards,
Manni

Print this item

  Examples for 12.9 - unary minus operator
Posted by: Manni - 24-04-2006, 12:00 PM - Forum: 6.12 Expressions - Replies (1)

Hi

Question about Rule 12.9: The unary minus operator shall not be applied to an expression whose underlying type is unsigned.

Code:
uint32_t u_int_a;
uint32_t u_int_b;

u_int_a = -u_int_b;
1. Is this incorrect?
2. Shows this example, what the rule 12.9 mean?



4. Is this correct? (a = int)
Code:
uint32_t int_a;
uint32_t u_int_b;

u_int_a = -(int32_t)u_int_b;


5. Is this correct, too? (a = uint)
Code:
uint32_t u_int_a;
uint32_t u_int_b;

u_int_a = -(int32_t)u_int_b;
6. I think it it is correct to rule 12.9, but breach 10.1. Right?


7. Have somebody good examples for rule breaks? And how to solve it?

best regards,
Manni

Print this item

Search Forums

(Advanced Search)

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

Full Statistics

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

Latest Threads
10.2.3 Amplification
Forum: 4.10 Declarations
Last Post: misra cpp
12-04-2024, 02:20 PM
» Replies: 1
» Views: 121
Rule 7.0.5 Example potent...
Forum: 4.7 Standard conversions
Last Post: misra cpp
12-04-2024, 01:54 PM
» Replies: 1
» Views: 109
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: 138
Further guidance on MISRA...
Forum: 8.10 The essential type model
Last Post: mshawa
09-04-2024, 02:29 PM
» Replies: 0
» Views: 48
MISRA AC SLSF:2023 AMD1
Forum: MISRA AC resources
Last Post: david ward
05-04-2024, 01:56 PM
» Replies: 0
» Views: 70
Rule 6-2-3 and C++17 [[fa...
Forum: 6.6 Statements (C++)
Last Post: kafka
27-03-2024, 02:44 PM
» Replies: 0
» Views: 106
MISRA AC GMG:2023 release...
Forum: MISRA AC GMG discussions
Last Post: misra-ac
25-03-2024, 06:01 PM
» Replies: 2
» Views: 413
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: 320
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,312
Rule 19.1 Example
Forum: 8.19 Overlapping storage
Last Post: misra-c
13-03-2024, 10:31 AM
» Replies: 3
» Views: 8,071