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

Username
  

Password
  





  Essential type of wchar_t?
Posted by: sca2012 - 21-11-2014, 03:18 PM - Forum: 8.10 The essential type model - Replies (1)

What is the essential category and rank of (implementation dependent) C99 type wchar_t?

Print this item

  size_t and Rule 3-9-2
Posted by: markturney - 21-11-2014, 02:34 PM - Forum: 6.3 Basic concepts (C++) - Replies (1)

Hello,

Rule 3-9-2 states that "typedefs that indicate size and signedness should be used in place of the basic numerical types."

It specifically states that "The basic numerical types of char, int, short, long, float, double and long double should not be used, but specific-length typedefs should be used."

What about size_t? The signedness is known, but the specific-length is not.

Does this code snippet violate 3-9-2?

Code:
std::vector collection(3, 5);

for (std::size_t ii = 0, count = collection.size(); ii < count; ++ii)
{
    processElement(collection[ii]);
}

Thank you for the help,
Mark

Print this item

  Essential rank of variabls and constants
Posted by: sca2012 - 20-11-2014, 06:47 PM - Forum: 8.10 The essential type model - Replies (1)

According p.8.10.2 and Appendix D, there are 5 ranks for signed and unsigned types for variables, defined, presumably, by their standard types. In particular, standard types int, long and long long are considered to have all different ranks.

According to p. D.3, for a constant, rank of its essential type is determined by its value. Now assume there is a (signed) constant that requires, say, 32 bits to represent the value. Is its rank the same as that of a signed int or signed long variable? And, correspondingly, for a 64-bit constant, will its rank be the same as that of signed long or signed long long variable?

Thank you.

Print this item

  Contacting MISRA Board
Posted by: igor.gvero - 12-11-2014, 02:30 PM - Forum: General Questions - Replies (1)

Hello everyone, I am a Product Manager/Owner at Klocwork/Roguewave and our developers had couple of questions with respect to rule interpretation.
Is there an email address I can use to contact someone who could answer this? Or appropriate board where I can get some information in a timely fashion.

Thank you!
Igor Gvero

Print this item

  Rule 11.3 - Unclear Example 3
Posted by: thohae - 10-11-2014, 03:27 PM - Forum: 8.11 Pointer type conversions - Replies (1)

The third and last example of Rule 11.3 states that

Code:
int * const * pcpi;
const int * const * pcpci;
pcpci = ( const int * const * ) pcpi;
Quote:is non-compliant because the unqualified pointer types are different, namely “pointer to const-qualified int” and “pointer to int”
But the rule's amplification explicitly states, that
Quote:This rule applies to the unqualified types that are pointed to by the pointers.
and that the rule's goal is to prevent misalignment.
I do not understand why the example is non-compliant, as the cast only adds a const-qualifier and leaves the base type as it is (i.e. "int").
Could you please explain this a little further?

Print this item

  else statement about Rule2.1
Posted by: KumikoItoh - 28-10-2014, 06:57 AM - Forum: 8.2 Unused code - Replies (2)

I have a question about Rule2.1.

Are these samples correct?
The else statement is null statement or not.

sample_1
if ( a= 5 ) {
y=3;
}else{
y=0; /* not compliant */
}

sample_2
if ( a= 5 ) {
y=3;
}else{
; /* compliant */
}

I think if the else statement is null statement the code is reachable.
Is is correct?

And how about is default label?

In case all case is coded,if default label has null statement , the code is reachable.
Is it correct?

Please teach me.

Regards

Print this item

  Rule 3-4-1 issues
Posted by: CGeddes - 16-10-2014, 01:22 PM - Forum: 6.3 Basic concepts (C++) - Replies (1)

We're having issues complying with rule 3-4-1 in a number of functions that initialise a temporary variable which is subsequently modified and tested within a loop. I appreciate in many cases this can be resolved with recursion, however, it seems an excessive solution given the additional considerations required.

The only other solution we've found (that doesn't conflict with other rules) is to declare and initialise a struct with the members set to the required values. e.g.

Code:
void f (void)
{
    struct FOO
    {
        int Index;
        int Result;
    } ;
    
    for (FOO Test = {0, 0}; Test.Index < 10; Test.Index++)
    {
        Test.Result += SomeTestFunction( );
    
        if (Test.Result > 5)
        {
            break;
        }
    }
}
What is the an 'expected' implementation of such functionality?

Print this item

  in the Example Suite, R_05_03.h
Posted by: ogawa.kiyoshi - 16-10-2014, 07:09 AM - Forum: 8.5 Identifers - Replies (1)

in the Example Suite, R_05_03.h

#ifndef R_05_09_
#define R_05_09_

should be

#ifndef R_05_03_
#define R_05_03_

BTW, now I compile the Example Suite using LLVM and add some supporting codes.
The memo for compile the Example Suite is
http://researchmap.jp/joydcij21-1861956/#_1861956

If there are any problems, please inform me.
I have updated weekly.

Print this item

  in the Example Suite, D_04_02.c
Posted by: ogawa.kiyoshi - 13-10-2014, 06:19 AM - Forum: 7.4 Code design - Replies (1)

In MISRA C:2012 Examples Suite, D_04_02.c has no function.
If you compile D_04_support.c or D_04_system.c then a link error should be occured.

For example, at LLVM(clang)
"_D_4_2", referenced from:
_D_4_main_support in D_04_support.o
_main in D_04_system.o
ld: symbol(s) not found

You could compile with adding a function D_4_2(){} in D_04_02.c or removing D_4_2( ); in D_04_support.c and D_04_system.c.

BTY.
In the Example suite, xx_system call xx_support, but both of them have same individual function calls.
it may be redundant.

Dr. OGAWA Kiyoshi

Print this item

  Rule 10.1 Small integer type operands of bitwise operators
Posted by: jeromeb - 10-10-2014, 07:11 AM - Forum: 8.10 The essential type model - Replies (2)

My static analyser tool throws a warning when small unsigned integer (short or char) operand is used with bitwise operator.

Code:
u16a = (uint16_t) ~u16b;

Static analyser warning : "Negative values cannot be stored as unsigned short. Coercing them to unsigned short can cause data loss or sign change."
Associated weakness : http://cwe.mitre.org/data/definitions/192.html and/or http://cwe.mitre.org/data/definitions/704.html

If I bypass integral promotion with cast to a widening type, the warning disappears;
Code:
u16a = (uint16_t) ~((unsigned int)u16b);

In ISO C99 draft 2007 (http://www.open-std.org/JTC1/SC22/WG14/w.../n1256.pdf) section J.3.5 "implementation-defined behavior", last item is :
Quote:The results of some bitwise operations on signed integers (6.5).

In MISRA C 2012, section 8.10, rule 10.1, Rationale item 6 :
Quote:Shift and bitwise operations should only be performed on operands of essentially unsigned type. The numeric value resulting from their use on essentially signed types is implementation-defined.

I don't understand why use of essentially type operands with bitwise operators can be implementation dependant while operators beahaviors are defined for standard type. In ISO C99, beahavior of bitwise operators is defined for standard type. I suppose after integral promotion ? Then, if small unsigned integers are used as operand with bitwise operators, operator works systematically with signed int after integral promotion. The behavior is implementation-dependant (two's or one's complement implementation can produce different results). Then, even with expected essentially type, I can obtain an implementation beahavior, no ?

Have I a bad interpretation of all standards (MISRA C, ISO C99, CWE, etc.) ?

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,173
» Latest member: SnakeLeon
» Forum threads: 998
» Forum posts: 2,752

Full Statistics

Online Users
There are currently 467 online users.
» 0 Member(s) | 465 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: 51
Rule 0.1.2
Forum: 4.0 Language independent issues
Last Post: stephanmuench
21-11-2024, 01:12 PM
» Replies: 0
» Views: 62
A18-9-4
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
23-10-2024, 12:04 PM
» Replies: 2
» Views: 418
A8-4-5: are partial moves...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
22-10-2024, 02:03 PM
» Replies: 1
» Views: 353
model information blocks ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:27 PM
» Replies: 1
» Views: 4,470
MISRA AL SLSF - Rule 043I
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:11 PM
» Replies: 1
» Views: 8,886
MISRA AC EC guidelines
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:21 AM
» Replies: 4
» Views: 15,561
News on future releases
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:05 AM
» Replies: 1
» Views: 5,717
Signal naming convention ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 07:57 AM
» Replies: 1
» Views: 7,276
Rule 7.0.2: operator cons...
Forum: 4.7 Standard conversions
Last Post: karos
14-10-2024, 08:52 PM
» Replies: 2
» Views: 473