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

Username
  

Password
  





  Can I get by with a little help from My Friends?
Posted by: gs - 12-09-2008, 06:50 PM - Forum: 6.11 Member access control (C++) - Replies (1)

Rule 11-0-1 states,

Quote:Member data in non-POD class types shall be private.
with the rationale:
Quote:By implementing class interfaces with member functions, the implementation retains more control over how the object state can be modified, and helps to allow a class to be maintained without affecting clients.
Does the above mean non-POD structure types should not contain any friend declarations? A friend declaration would by definition allow for the circumvention of the access restrictions.

Print this item

  Proverbially Playing the `Devil's Advocate' for Rule 15-1-2
Posted by: gs - 11-09-2008, 06:46 PM - Forum: 6.15 Exception handling (C++) - Replies (1)

The text and rationale of rule 15-1-2 make no mention of the word `macro'. Let us suppose an application made no reference to the Standard Library within it's source code. Consequently, the `NULL' macro has not been defined. Would the following code violate rule 15-1-2?

Code:
class A {};
A NULL;
void f()
    {
    throw NULL;
    }
The very premise of the rationale for the rule is invalid. In this case a `throw NULL;' is not equivalent to `throw (0);' and is not a throwing of an integer expression.

Furthermore, the wording of the rationale is slightly incorrect:
Quote:throw(NULL) (equivalent to throw(0)) is never a throw of the null-pointer-constant ...
To quote ISO C++, 18.1, para. 4, (lib.support.types):
Quote:The macro NULL is an implementation-defined C++ null pointer constant in this International Standard
(4.10).
Granted, the referenced `4.10' states a null pointer constant has integer (not pointer) type. However, the macro is a null pointer constant.

Print this item

  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

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 221 online users.
» 0 Member(s) | 219 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: 37
Rule 0.1.2
Forum: 4.0 Language independent issues
Last Post: stephanmuench
21-11-2024, 01:12 PM
» Replies: 0
» Views: 46
A18-9-4
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
23-10-2024, 12:04 PM
» Replies: 2
» Views: 399
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,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,523
News on future releases
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:05 AM
» Replies: 1
» Views: 5,707
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: 449