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

Username
  

Password
  





  Booleans and the unterlying type
Posted by: gunter.blache - 15-02-2010, 10:34 AM - Forum: 6.10 Arithmetic Type Conversions - Replies (6)

There are no boolean types in C and I assume that rule 10.x also apply to boolean expressions. The question now is how to make
boolean expressions compliant to these rules.
If there are variables boolU8 and boolS8 which are of type unsigned char and signed char are represent boolean values, and assignment
will require an explicit cast:
boolU8 = (uint8)boolS8;
No problem here.

Boolean operators &&, || and ! yield a result of type "int" (MISRA-C:2004 page 37 3rd paragraph), which confuses me a little bit,
because I expected the guideline to specify an "underlying type" instead of a real type.
So to have a simple assignment like
boolU8 = c && d;
compliant, I have to downcast to the result to uint8, which requires a temporary variable (according to rule 10.3):
int _t = c && d;
boolU8 = (uint8)_t;

The is no more safe than the simple assignment, a lot less readable and involves the plain type "int", which violates rule 6.3 (typedefs
should be used in place of the basic types).

I did not find anything on this subject in the technical corrigendum, nor does the entry in the glossary on "boolean expressions" help
with type casting.

Any thoughts ?

Print this item

  Improving Software Safety through MISRA
Posted by: ybenezra - 04-02-2010, 09:31 AM - Forum: General Questions - Replies (1)

I need to provide an objective evidence showing that Software safety is improved by compliance to MISRA-C rules. The provided evidence should include quantitative measurements that show safety improvement after the application of MISRA-C rules. Please help.

Print this item

  "char" vs. "signed char" vs. "unsigned char" in rule 10.5
Posted by: andersl - 01-02-2010, 11:00 AM - Forum: 6.10 Arithmetic Type Conversions - Replies (4)

In C, there are three types of characters: "char", "signed char", and "unsigned char". (The representation of the type "char" is either signed or unsigned). Note that this makes characters different than the other integer types as, for example, "short" is a synonym for "signed short".

Rule 10.5 states "if the bitwise operators ~ and

Print this item

  IEC 26262
Posted by: ggentile - 31-01-2010, 07:38 PM - Forum: MISRA AC GMG discussions - Replies (7)

Hi Board,

exist any relation/ raccamandation in IEC 26262 to follow the new MISRA AC rules ?

Thanks Giacomo

Print this item

  Rule 10.5 clarification
Posted by: c-addison - 30-12-2009, 10:09 PM - Forum: 6.10 Arithmetic Type Conversions - Replies (5)

The description of rule 10.5 mentions that the operators must be applied to "small integer types" for the casts to be required. The types unsigned char and unsigned short are mentioned explicitly. What if char, short, and int are all the same size on the machine? In that case is OK to not perform the required cast? This really comes down to whether or not we should be checking for the unsigned char and unsigned short types explicitly or instead should check for all types which have a a narrower type than int.

Print this item

  switch
Posted by: ggentile - 08-12-2009, 08:23 PM - Forum: MISRA AC SLSF discussions - Replies (1)

It seems to me that any restriction are applied to switch block.

Is admited to switch between differnt type of signal:
float/boolena
int/bool
int/float

Instead GMG rules suggest the user to use types properly.

Giacomo

Print this item

  wrong use of type float
Posted by: ggentile - 08-12-2009, 08:19 PM - Forum: MISRA AC SLSF discussions - Replies (1)

I didn't found any explicit rule that prohibit a misleading use of float

1) float as vector index into stateflow/simulink
2) logical operation between float in stateflow and simulink

General Modelling rules cover this topic but SLSF seems to me not!

May you confirm that I've properly read the standard ?

Giacomo

Our concern is also related to unoptimized code that should be produce by these bad modelling style

Print this item

  Violations of rules 11.1, 11.2, 11.3, 11.4
Posted by: adytzul_ac - 25-11-2009, 12:40 PM - Forum: 6.11 Pointer Type Conversions - Replies (5)

Hello.
My PC-LINT tool gives me an error of violating of rules 11.1, 11.2, 11.3, 11.4 (cast from unsigned char to pointer ) on the line 2:

line 1: unsigned char* ptr;
line 2: ptr=(unsigned char*)0x12;

The idea behind is that I want to initialize a pointer with a non-zero address in a MISRA-compliant style.

Thank you for the answer.

Best regards.

Print this item

  2 questions for rule 18.1
Posted by: pmhill - 25-11-2009, 09:22 AM - Forum: 6.18 Structures and Unions - Replies (2)

The rule applies to structure definitions that are incomplete, but I see from exemplar suite file mc2_1801.c the following unexpected violation:

struct {
int8_t a;
int8_t b [ ]; /* Not Compliant - constraint error 6.5.2.1 */
} mc2_1801_st = { 1, { 2, 3, 4 } };

Are you including as "incomplete" any structure that has a flexible array member?

Apart from this, what other coding practice is left that might cause a problem?

If the type is incomplete, a compile error will result from any attempt to create an object of that type or refer to its members or to compute sizeof, etc.

So I cannot think of any legal C code that would be a violation of this rule.

Print this item

  Rule 3-1-1 and constant declarations
Posted by: MarkCotton - 18-11-2009, 06:08 PM - Forum: 6.3 Basic concepts (C++) - Replies (2)

I have been using PCLint to analyse code which have constants defined in header files e.g.

const uint8 PLD_READ_VERIFICATION_BYTE_4 = 7;

PCLint claims that this violates rule 3-1-1. Is this a true interpretation of this rule or are constants permitted in header files?

Mark.

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 300 online users.
» 0 Member(s) | 297 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: 35
Rule 0.1.2
Forum: 4.0 Language independent issues
Last Post: stephanmuench
21-11-2024, 01:12 PM
» Replies: 0
» Views: 44
A18-9-4
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
23-10-2024, 12:04 PM
» Replies: 2
» Views: 395
A8-4-5: are partial moves...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
22-10-2024, 02:03 PM
» Replies: 1
» Views: 338
model information blocks ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:27 PM
» Replies: 1
» Views: 4,459
MISRA AL SLSF - Rule 043I
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:11 PM
» Replies: 1
» Views: 8,875
MISRA AC EC guidelines
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:21 AM
» Replies: 4
» Views: 15,522
News on future releases
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:05 AM
» Replies: 1
» Views: 5,706
Signal naming convention ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 07:57 AM
» Replies: 1
» Views: 7,258
Rule 7.0.2: operator cons...
Forum: 4.7 Standard conversions
Last Post: karos
14-10-2024, 08:52 PM
» Replies: 2
» Views: 448