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

Username
  

Password
  





  Rule 3-4-1 and defining constants in one place
Posted by: rrosier - 26-07-2018, 12:28 PM - Forum: 6.3 Basic concepts (C++) - Replies (3)

If one were to use the strategy of defining all the constants used within a file at the top of the file, either as static const or in an unnamed namespace, but some of the constants are used in multiple places and others are only used in single places, then those that are only used in single places will violate Rule 3-4-1.

If those that are used only in single places are subsequently moved into blocks with reduced scope, then the constants are scattered around the file.

This could create a maintenance headache because it is more difficult for a developer to find a constant.

Furthermore, if a developer needs to use a singly-used constant now in another place, they might not realise that the constant has already been defined (and then widen its scope) but instead add in a new singly-used constant of reduced scope in the new place.

It there some way to put all of the defined constants into a well-known location, but then not violate Rule 3-4-1 for the singly-used ones?

Print this item

  Memory allocation when throwing an exception.
Posted by: apasternak - 24-07-2018, 12:15 PM - Forum: 6.15 Exception handling (C++) - Replies (1)

Dear all

While doing a memory audit of our framework for autonomous driving cars we realized that throwing any kind of exception dynamically allocates memory on compilers using the Itanium C++ ABI (notably gcc and clang). Further, throwing an exception may block for which is not acceptable for safety-critical real-time systems.

Neither Misra 2008 nor Autosar 14 or other guidelines forbid exceptions in safety-critical environments. What were the considerations when investigating this issue?

To solve this issue we created a library which replaces the dynamic memory allocation with a memory pool. This library is freely available here: https://github.com/ApexAI/static_exception

Any inputs or other approaches would be very welcome!

Best regards,

Andreas

Print this item

  3-9-2 and auto in future MISRA C++14
Posted by: dg1980 - 20-07-2018, 07:32 AM - Forum: 6.3 Basic concepts (C++) - Replies (3)

Hi,

as stated here (https://misra.org.uk/forum/viewtopic.php...1504#p3404) the next version of MISRA C++ will be based on ISO C++14.
I am curious if you already came to a decision on whether to allow or prohibit the auto keyword for automatic type deduction?
While it is certainly more convenient to write code, i would imagine performing a code review or adapting a static analysis tool would become more challenging.

Print this item

  Rule 10.1
Posted by: phdenis - 18-07-2018, 09:30 AM - Forum: 6.10 Arithmetic Type Conversions - Replies (4)

Hello all,

I've an error 10.1 on the following C code:

Code:
#define MyConst 0x8A

My Code Review checker asks to add a U to the constant.

I'm quite surprised if it was a decimal value, I'll understand it but for an hexa, I don't really understand why ?

Another question is to know if a test set is present on the MISRA community to check the correct behaviour of the Code Review tool.

By advance thanks for your help.

B/R
Philippe

Print this item

  MISRA C++ new version
Posted by: ptalwar - 13-07-2018, 09:15 PM - Forum: C++ Announcements - Replies (8)

Is MISRA going to release a new version for C++14 anytime soon?
If so, what does the timeline look like and when it's going to be made available to public?

Print this item

  Why is rule 1.2 classified as undecidable?
Posted by: dg1980 - 13-07-2018, 06:31 AM - Forum: 8.1 A standard C environment - Replies (1)

All you have to do is check the syntax/keywords against the C language standard?
It is even possible with some compilers (e.g. a strict mode)?

Print this item

  5-2-7 and void pointer conversions
Posted by: rgamble - 13-07-2018, 02:32 AM - Forum: 6.5 Expressions (C++) - Replies (1)

Are conversions between pointers to void and pointers to object types a violation of rule 5-2-7? It isn't clear what "object with pointer type" means here (or "unrelated pointer type" for that matter). Specifically, are either of the casts below a violation of Rule 5-2-7?

Code:
void bar(int *ip, void *vp) {
    ip = static_cast(vp);
    vp = static_cast(ip);
}

Print this item

  Conversions outside of the essential type categories
Posted by: gdavis - 10-07-2018, 11:26 PM - Forum: 8.10 The essential type model - Replies (1)

Hello,

With respect to the essential type rules, do conversions to types that are outside the essential type categories count as violations of the rules? For example:

Code:
#include
char buf[80];
char *p = buf;
uintptr_t p_plus_one;
void foo(void);
void foo(void) {
    // This next statement violates R11.4.  But does
    // it violate R10.8?  As a pointer type, p+1 does not
    // have a clear essential type category.
    p_plus_one = (uintptr_t)(p+1);
}
On the one hand, the spirit of the rule seems like it should prohibit such things. On the other hand, TC1 amends rule 10.1 to describe how a pointer type may not be used as an operand of a logical operator.

Thank you for your time.

-Greg

Print this item

  Chapter 6.6.5 Iteration statements
Posted by: sklinger - 06-07-2018, 11:03 AM - Forum: 6.6 Statements (C++) - Replies (2)

Hello,

Regarding the rules 6-5-1, 6-5-2, 6-5-3, 6-5-4, 6-5-5, 6-5-6:
Do these rules only apply to for-loops or do they also apply to while-loops?

best regards,
Stefan

Print this item

  Rule M16.10
Posted by: phdenis - 04-07-2018, 10:47 PM - Forum: 6.10 Arithmetic Type Conversions - Replies (2)

Hello all,

I'm using the Misra 2004:C rules for the 1st time (e.g. I'm a newbie) and I got several errors linked to the rule M16.10 when I'm using the strncpy function like that:

Code:
strncpy(MyStr1,MyConstStr, sizeof(MyConstStr);

I've fixed this error by adding a pointer to the code which is not used.

Code:
char *MyPtr;
MyPtr = strncpy(MyStr1,MyConstStr, sizeof(MyConstStr);

So my question is:
For the functions like strncpy, memset and others functions of the same style, do we need to fix the misra error or do we have to justify it plainly?

By advance, thanks for your help.

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 150 online users.
» 0 Member(s) | 146 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: 427
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: 723
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: 436
M5-0-4 switch over unscop...
Forum: 6.5 Expressions (C++)
Last Post: misra cpp
25-09-2026, 01:00 PM
» Replies: 3
» Views: 536