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

Username
  

Password
  





  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

  writing a MISRA-C:2004 tutorial
Posted by: Manni - 19-04-2006, 01:09 PM - Forum: General Questions - Replies (9)

Hi

I want to start writing a helping document and tutorial about MISRA-C:2004 rules. The document should contain the following points.

1. Reasons for specific MISRA-C rules. (Why is it important to observe the rule)
2. Howto handle specific rules
3. Howto conceive specific rules
4. Exampels for breaches of the specific rules, and how to solve it. (with example, too)

Are there any good sources and publications, which helping to write such a tutorial?

best regards,
Manni

EDIT:
I know that there are explanations like this in miscra-c rules included. But I mean more comprehensive explanation.

Print this item

  Welcome
Posted by: david ward - 07-04-2006, 10:34 AM - Forum: MISRA SRfP Discussions - Replies (1)

This new forum has been set up for asking questions about and discussing MISRA's \"Software Readiness for Production\" guidelines.

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,172
» Latest member: jeongsang kim
» Forum threads: 998
» Forum posts: 2,752

Full Statistics

Online Users
There are currently 205 online users.
» 1 Member(s) | 199 Guest(s)
Bing, Facebook, Google, Twitter, Yandex, podp

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: 38
Rule 0.1.2
Forum: 4.0 Language independent issues
Last Post: stephanmuench
21-11-2024, 01:12 PM
» Replies: 0
» Views: 52
A18-9-4
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
23-10-2024, 12:04 PM
» Replies: 2
» Views: 401
A8-4-5: are partial moves...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
22-10-2024, 02:03 PM
» Replies: 1
» Views: 339
model information blocks ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:27 PM
» Replies: 1
» Views: 4,460
MISRA AL SLSF - Rule 043I
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:11 PM
» Replies: 1
» Views: 8,876
MISRA AC EC guidelines
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:21 AM
» Replies: 4
» Views: 15,530
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,261
Rule 7.0.2: operator cons...
Forum: 4.7 Standard conversions
Last Post: karos
14-10-2024, 08:52 PM
» Replies: 2
» Views: 452