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

Username
  

Password
  





  Making constants in MISRA compliant C++
Posted by: Insane Vent Storm - 09-11-2015, 01:52 PM - Forum: 6.1 General (C++) - Replies (8)

I am trying to declare a constant for use in fixing the size of several C++ arrays. I have tried 3 options:
1) #'define MaxTracksConst 8

2) const Rhp_int32_t MaxTracksConst(8);

3) enum %s {one, two, three, four, five, six, seven, MaxTracksConst}

but our LDRA MISRA checker finds fault with all of them ( 1. fails 16-2-2, 2. fails 3-1-1 and 3. fails 4-5-2 ).
Am I missing something, or is there an option that will pass MISRA C++ 2008 checks ?

Kind regards
Insane Vent Storm

Print this item

  Rule 8.4: Prototype for function with internal linkage required?
Posted by: aletomm - 04-11-2015, 02:51 PM - Forum: 8.8 Declarations and defnitions - Replies (1)

Does MISRA-C 2012 mandate prototypes for functions with internal linkage?

While MISRA-C 2012 rule 8.4 is very explicit about prototypes for functions with external linkage, we have not found a corresponding rule for internally linked functions.

Our static analysis tool takes the simplistic approach that prototypes are required in any case due to MISRA-C 2004 8.1 rule. I like to challenge its reasoning.

Thanks.

Print this item

  5.5 and groups of preprocessing
Posted by: lovewar - 03-11-2015, 06:44 AM - Forum: 8.5 Identifers - Replies (1)

such as

Code:
#ifndef NO_TAG
static void log (const char *format, ...)
{
}
#else
#if defined(__STDC_VERSION__)
#define log(...) do { } while (0)    // here
#endif
#endif
and, the identifier(log) exists after preprocssing has been performed:
Code:
static void log (const char *format, ...)   // does it apply to #define log ?
{
}
I have a question regarding rule 5.5: does the function(log) apply to #define log ?

Print this item

  Rule 2.4 and tag used in typedef
Posted by: lovewar - 30-10-2015, 09:05 AM - Forum: 8.2 Unused code - Replies (2)

Would the following examples be compliant with rule #2.4?

Code:
typedef struct cood cood_t;
struct cood {                    // here,  is the tag "cood" compliant?
    uint8_t  id;
};

Print this item

  10.5 Iterating over an enum
Posted by: dermiem - 29-10-2015, 04:32 PM - Forum: 8.10 The essential type model - Replies (2)

I usually define a enum in a project specific H file, to represent a set of signals:
typedef enum {
ADC_VBAT
ADC_FEEDBACK,
ADC_VOLTAGE,

ADC_NUM_SIGNALS
} adc_t ;

And then in the reusable C file, iterate over the configured set of signals. For example, to set the initial value of the averaged signal:

uint8_t i ;

for (i=0U; i < (uint8_t) ADC_NUM_SIGNALS; i++)
{
AdcClearAverage((adc_t) i) ;
}

where AdcClearAverage takes a parameter of type adc_t.

But this now generates warning 10.5 as an unsigned type is being cast to an enum.
What is the correct way to iterate over an enumeration?

Print this item

  Rule 19.1 and assignment of one element of array
Posted by: lovewar - 29-10-2015, 05:41 AM - Forum: 8.19 Overlapping storage - Replies (1)

Would the following examples be compliant with rule #19.1?

Code:
int16_t a[20];
void g(void)
{
    int16_t *p = &a[0];
    int16_t *q = &a[0];
    *p = *q;              /* Compliant - exception 1 */
}
void f(void)
{
    int16_t *p = &a[0];
    int16_t *q = &a[1];
    *p = *q;                     // here, is it Compliant ?
}

Print this item

  Rule 10.3 Does exception 1 apply to case labels?
Posted by: grunwald - 15-10-2015, 12:30 PM - Forum: 8.10 The essential type model - Replies (2)

Rule 10.3 covers assignment (as defined in the glossary) and the conversion of the constant expression in case labels.

Exception 1 says "A non-negative integer constant expression of essentially signed type may be assigned to an object of essentially unsigned type if its value can be represented in that type."

Is this exception intended to be restricted to assignment; or does it also apply to case labels?

Code:
switch (u8a) // controlling expression is essentially unsigned
{
    case 1: break; // '1' is essentially signed; 10.3 violation?
    case 2: break;
    default: break;
}

Print this item

  10.3 and essential type of & expression
Posted by: lovewar - 15-10-2015, 05:54 AM - Forum: 8.10 The essential type model - Replies (1)

Would the following examples be compliant with rule #10.3?

Code:
void foo(void) {
  uint8_t u8a = getCode();
  
  sint32_t s32a = u8a & 0xFF;    // here
}

Would the following examples be non-compliant with rule #10.3?
Code:
void foo(void) {
  uint8_t u8a = getCode();
  
  uint8_t u8b = u8a & 0xFF;    // here
}

Print this item

  Rule 18.4, 10.1, and the "type" of pointer to object
Posted by: michael.metivier - 01-10-2015, 06:48 PM - Forum: 8.18 Pointers and arrays - Replies (1)

Within our development group, there has been some discussion as to whether or not the construction

Code:
void test(uint8_t * up)
{
    bool invalid = !up;
    ...
}
is valid with regard to the usage of '!' against a pointer. According to the 18.X rules, '!' is not disallowed for use on pointers, but the explanation of Rule 10.1 with regards to the appropriate essential type for use with '!' would indicate that, as a non-Boolean, its use on pointers should be disallowed.

Do pointers have an "essential type" under the essential type model and what is the correct interpretation in this case?

Print this item

  Rule 5.9 - Scope of uniqueness
Posted by: jade - 11-09-2015, 04:49 PM - Forum: 8.5 Identifers - Replies (2)

In Rule 5.9, the amplification says that the identifier name should be unique across all name spaces and translation units. This is an expansion of what's in the rule header, but is consistent with the purpose of the "Amplification" sections. However, the examples imply that identifiers can be unique if there is no linkage. Isn't this a contradiction?

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) | 298 Guest(s)
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: 23
Rule 0.1.2
Forum: 4.0 Language independent issues
Last Post: stephanmuench
21-11-2024, 01:12 PM
» Replies: 0
» Views: 34
A18-9-4
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
23-10-2024, 12:04 PM
» Replies: 2
» Views: 365
A8-4-5: are partial moves...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
22-10-2024, 02:03 PM
» Replies: 1
» Views: 321
model information blocks ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:27 PM
» Replies: 1
» Views: 4,441
MISRA AL SLSF - Rule 043I
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:11 PM
» Replies: 1
» Views: 8,860
MISRA AC EC guidelines
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:21 AM
» Replies: 4
» Views: 15,497
News on future releases
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:05 AM
» Replies: 1
» Views: 5,690
Signal naming convention ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 07:57 AM
» Replies: 1
» Views: 7,245
Rule 7.0.2: operator cons...
Forum: 4.7 Standard conversions
Last Post: karos
14-10-2024, 08:52 PM
» Replies: 2
» Views: 429