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

Username
  

Password
  





  What is the intention of the rule 18-0-1?
Posted by: nakagawat - 11-09-2008, 01:03 PM - Forum: 6.18 Language support library (C++) - Replies (1)

The Rule 18-0-1 of the MISRA-C++:2008 prohibits developers from using
C libraries entirely. At the same time, the 'Rationale' section of this
rule admits the use of the C++ libraries which correspond to C libraries.

Many of the C++ libraries corresponding to C libraries are defined
as the C libraries surrounded by the std namespace. For the reason,
we think even if the C++ libraries corresponding to C libraries
are used, it is impossible to avoid such vulnerability C libraries
have as undefined behavior and unspecified behavior.

Why does the Rule 18-0-1 admit the use of the C++ libraries corresponding
to C libraries?

Print this item

  14.10 Hiding an else if construct
Posted by: brian_bassil - 10-09-2008, 12:13 PM - Forum: 6.14 Control Flow - Replies (1)

The following

Code:
if ( x < 0 )
{
    log_error(3);
    x = 0;
}
else if ( y < 0 )
{
   x = 3;
}
else
{
/* no change */
}

Can be coded as

Code:
if ( x < 0 )
{
    log_error(3);
    x = 0;
}
else
{
   if ( y < 0 )
   {
      x = 3;
   }
}

to hide the "else if". Is this OK?

I think the code blocks are semantically identical but the last one does not list the else.

Brian

Print this item

  Do implicitly generated copy-assignment operators count?
Posted by: gs - 09-09-2008, 05:31 PM - Forum: 6.12 Special member functions (C++) - Replies (1)

Rule 12-8-2 states:

Quote:The copy assignment operator shall be declared protected or private in an abstract class.
Does this prohibition also include the implicitly generated copy assignment operator? When implicitly generated, ISO C++, 12.8, p. 10, states:
Quote:An implicitly-declared copy assignment operator is an inline public member of its class.
So, does the following code comply with rule 12-8-2:
Code:
class A
    {
    virtual void b() = 0;
    };
?

Print this item

  13.5 clarification on loop index iusage
Posted by: Alexandre Langenieux - 04-09-2008, 09:23 AM - Forum: 6.13 Control Statement Expressions - Replies (2)

Dear Misra Committee,

Rule 13.5 seems not clearly explicit about the content of the for expressions.

  • First expression: Initialization of the loop coounter if present. Can we consider as valid code the following examples:
    [code]
    int32_t i=0;

    for (i++;i

Print this item

  Rule 13.4 clarification
Posted by: Alexandre Langenieux - 01-09-2008, 03:38 PM - Forum: 6.13 Control Statement Expressions - Replies (1)

Dear Misra committee,

The rule 13.4 says:
The controlling expression of a for statement shall not contain any objects of floating type.

Does it apply only to loop counter, as suggest in the text explaining the rule ( ... floating-point variables shall not be used for this purpose [loop counter] ...). or to all operand of a controlling expression ?

I mean, can we consider the following for loop as compliant ?

Code:
extern float32_t foo(void);

int32_t i;
float32_t f;

for (i=0; i 1.0 && f < 3.0) ; i++){
  ...
  f = foo()
  ...
}

Thanks, Alexandre.

Print this item

  Confusion over rule 17-0-3
Posted by: gs - 25-08-2008, 07:43 PM - Forum: 6.17 Library introduction (C++) - Replies (3)

Hi,

For rule 17-0-3, I see only two scenarios where the guidelines permit overloading a standard library function. (Note: I presume by 'overridden', the guidelines actually mean over 'overloaded', since only virtual member-functions may be 'overridden'. Do correct me, if I err in that assessment.)

The first scenario involves the addition of parameters to the function. The text

Quote:However, it is permissible to overload the name to add new parameter types if the functionality is consistent with those of the original.
makes this statement prima facia true.

The second scenario involves replacing a parameter type with a non-library type, implied by the sentence
Quote:It is permissible to add a new sqrt function for a type not present in the library.

Therefore, we find the following code compliant:

Code:
// Standard library code, simplified for this discussion
template  class vector{};
void memcpy( char *, char *, int );
// Non-library code
class A{};
void memcpy( char *, char *, int, int );  // Ok, extra parameter.
void memcpy( A, char *, int );  // Ok, non-library type for a parameter.

Meanwhile the following would not (the above code is presumed given):

Code:
void memcpy( vector, char *, int );  // !Ok, library type for a parameter.

What of built-in types? Technically, the built-ins are not part of the library. They are built-in. So, would this could comply with the rule? (The above, again presumed.)

Code:
void memcpy( char*, char *, long );

If the two scenarios are the only ones permitted, a rule as straightforward as,

Quote:Standard library functions shall not be overloaded, except to add parameters or to substitute a non-library type for any of the parameters.
One would expect, would have sufficed.

The fact MISRA chose to provide a rationale requiring a longer logic train, implies other scenarios are permitted. However, as I mentioned, I cannot conceive of such at this moment.

Additionally, the rationale makes no mention of how to handle standard library functions which include ellipses in there parameter lists. How should programmers handle such situations?

Lastly, the ISO C++ standard, 17.4.2.2 p2 (lib.using.linkage), states,
Quote:It is implementation-defined whether a name from the Standard C library declared with external linkage has extern "C" or extern "C++" linkage. It is recommended that an implementation use extern "C++" linkage for this purpose.
which recommends, but does not require extern "C++" linkage. Combine this fact with ISO C++, 7.5 p6 (dcl.link),
Quote:At most one function with a particular name can have C language linkage.
and One must ask if such circumstances were considered in the drafting of this rule. (I feel reasonably confident the circumstances were considered. The wording of the rationale, simply put, does not make any suggestion one way or the other.)

Print this item

  Confusion over enum type expressions
Posted by: gs - 21-08-2008, 06:57 PM - Forum: 6.7 Declarations (C++) - Replies (1)

Hi,
The rationale for rule 7-2-1 states,

Quote:It is unspecified behaviour if the evaluation of an expression with enum underlying type yields a value which does not correspond to one of the enumerators of the enumeration.
This assertion contains a slight inaccuracy. The relevant section of the ISO C++ (2003) standard, 7.2(9), actually reads,
Quote:An expression of arithmetic or enumeration type can be converted to an enumeration type explicitly. The value is unchanged if it is in the range of enumeration values of the enumeration type; otherwise the resulting enumeration value is unspecified.
(emphasis added by this Poster).

Should the MISRA C++ rule, instead, read,
Quote:An expression with enum underlying type shall only have values within the range of the enumerators of the enumeration.
(emphasis, again, added by this Poster)?

Print this item

  Rule 113 Clarification
Posted by: gs - 13-08-2008, 05:12 PM - Forum: General Questions - No Replies

The meaning of 113:1998 seems rather vague to me. Could anyone elaborate on the specifics the rule intends to prohibit?

Print this item

  Incorrect comment in mc2_2001.c
Posted by: william.forbes - 25-07-2008, 11:01 AM - Forum: MISRA-C:2004 Exemplar Suite - Replies (1)

In line 42

Quote:/* 7.13.3 to* where * is a lower case letter */
should read
Quote:/* 7.13.2 to* where * is a lower case letter */
i think.

Bill Forbes.

Print this item

  Preprocessor directives and white space
Posted by: JonM - 25-07-2008, 09:45 AM - Forum: 6.19 Preprocessing Directives - Replies (1)

Rule 19.16 of MISRA C2 requires "In particular, ensure that #else and #endif directives are not followed by any characters other than white-space."

Does this rule apply to the end of the line or just the character following the 'e' or 'f'.

e.g.

Code:
#endif
/* header file exclusion */
vs
Code:
#endif /* header file exclusion */
vs
Code:
#endif/*header file exclusion */

Which of these is allowed / preferred / not allowed by MISRA C

Jonathan

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,309
» Latest member: 1fuhd
» Forum threads: 1,066
» Forum posts: 2,933

Full Statistics

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

Latest Threads
13.2 Was TC2 correctly ap...
Forum: 8.13 Side effects
Last Post: misra-c
08-10-2026, 12:47 PM
» Replies: 1
» Views: 624
20.12 Does the stringific...
Forum: 8.20 Preprocessing directives
Last Post: misra-c
08-10-2026, 12:40 PM
» Replies: 1
» Views: 554
13.3 Should side effects ...
Forum: 8.13 Side effects
Last Post: misra-c
08-10-2026, 12:37 PM
» Replies: 1
» Views: 426
11.6 pointer to pointer t...
Forum: 8.11 Pointer type conversions
Last Post: misra-c
08-10-2026, 12:21 PM
» Replies: 2
» Views: 1,032
What is the UTLR of -1?
Forum: 8.10 The essential type model
Last Post: misra-c
08-10-2026, 12:15 PM
» Replies: 1
» Views: 597
10.3 Clarify if narrower ...
Forum: 8.10 The essential type model
Last Post: misra-c
08-10-2026, 11:57 AM
» Replies: 1
» Views: 508
It 8.12 intended to be so...
Forum: 8.8 Declarations and defnitions
Last Post: misra-c
08-10-2026, 11:50 AM
» Replies: 1
» Views: 455
Rule 0.1.1 Example f4
Forum: 4.0 Language independent issues
Last Post: cgpzs
07-10-2026, 11:07 AM
» Replies: 3
» Views: 720
Rule 6-2-2 Usage of std::...
Forum: 6.6 Statements (C++)
Last Post: misra cpp
25-09-2026, 05:43 PM
» Replies: 1
» Views: 435
M5-0-4 switch over unscop...
Forum: 6.5 Expressions (C++)
Last Post: misra cpp
25-09-2026, 01:00 PM
» Replies: 3
» Views: 533