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

Username
  

Password
  





  Rule 2-5-1
Posted by: ogawa.kiyoshi - 01-10-2017, 01:31 AM - Forum: 6.2 Lexical conventions (C++) - Replies (1)

I feel, the sentence "The use of digraphs may not meet developer expectations." is not clear.
The usage of digraphs are only system constraints.
Digraph are just an alternative method for a systems that can not input '{','}','[',']'.
Therefore, there is no point in leaving a digraph in the final source file.
Even if anyone use a system that requires digraphs, it is better to replace in the final source file from digraph(alternative token) to primary token.

Print this item

  Underlying type of sum of constants
Posted by: abgs - 29-09-2017, 01:55 PM - Forum: 6.5 Expressions (C++) - Replies (2)

Consider:

namespace {
typedef unsigned short ui16;
const ui16 x = 1U;
const ui16 y = 2U;
const ui16 z = x + y;
}

Page 55 of MISRA C++ states:

"The underlying type of an integer constant expression is therefore defined as follows: 1. If the actual type of the expression is signed integral, the underlying type is defined as the smallest signed integer type that is capable of representing its value."

* The actual type of x + y is int
* The value of x + y is three
* The smallest signed type capable of representing three is signed char
* The underlying type of x + y is signed char

This also seems to match the behavior on page 60:

"The underlying type for a constant expression “e” with a value “v” will have the same signedness as “e”, and a magnitude given by the underlying type of a single integer-literal with the same value as “v”." (referring to page 58 "The underlying type of an integral literal is the smallest fundamental type of the appropriate sign required to store its value.")

where:

* "e" is x + y
* The actual type of "e" is int (determining signedness)
* "v" is three
* The underlying type of an integer literal with the value three is signed char (determining magnitude)
* The underlying type of x + y is signed char

Is this interpretation correct?

Print this item

  Normative power of misra-c answers
Posted by: Mark Alexander - 27-09-2017, 04:14 PM - Forum: General Questions - Replies (1)

Hello everyone,
as stated in: https://www.misra.org.uk/forum/viewtopic...2334#p2334 official answers (i suspected and hope only via the misra-c account) have normative power. This decision is impractical (for me), as we will have to set up a task to perform an check regularly if the standard has been corrected or otherwise updated via an answer; but this can be done. I would like you to ask however 2 favors:

1) As the above linked answer was in the MISRA-C:2004 sub-forum, can you please point out and confirm the normative power for the whole of the MISRA-C discussions at a prominent place?

2) As consistency and completeness is quite hard to obtain just by studying the comments, could you please systematically add additional information for each of the misra-c user answers,
- if they contain normative content (not all do!) or not,
- if the normative content is (still) valid or deprecated
- if the normative content is deprecated, by what it was invalidated (e.g. a other comment, a MISRA-C TC, new edition...)

With regards,
Mark Alexander

Print this item

  Rule 11.9: Does this struct initialization violate rule 11.9?
Posted by: fst-mra - 27-09-2017, 10:09 AM - Forum: 8.11 Pointer type conversions - Replies (2)

Dear community,

our analysis tool reports the following struct initialization to violate rule 11.9 (macro NULL is the only permitted form of integer null pointer constant):

static const myType myStruct = {
64,
{0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0},
0
};

with:
typedef unsigned short uint16;
typedef unsigned char uint8;
typedef struct {
uint16 myVariable01;
uint8 myArray [16];
uint8 myVariable02;
} myType;

Unfortunately, neither from the tool documentation nor from the MISRA documentation we can conclude why this initialization would be non-compliant. Also we cannot see what the risk behind this deviation would be. Is this deviation false-positive? Does it introduce any portability, maintainability etc. risk?

Thanks for your support.
Frank

Print this item

  Rule 11.9: Does array initialization to 0 violate Rule 11.9?
Posted by: fst-mra - 27-09-2017, 10:00 AM - Forum: 8.11 Pointer type conversions - Replies (1)

Dear community,

our analysis tool reports the following array initialization to violate rule 11.9 (macro NULL is the only permitted form of integer null pointer constant):

uint8 myBuffer[8] = {0u}; // with "typedef unsigned char uint8;"

Unfortunately, neither from the tool documentation nor from the MISRA documentation we can conclude why this "standard" construct would be non-compliant. Also we cannot see what the risk behind this deviation would be. Is this deviation false-positive? Does it introduce any portability, maintainability etc. risk?

Thanks for your support.
Frank

Print this item

  essential type of constant expression
Posted by: sowiso - 26-09-2017, 12:01 PM - Forum: 8.10 The essential type model - Replies (1)

In Appendix D.1 the following limitation for the paragraphs D.n:

Quote:The essential type of an expression only differs from the standard C type (standard type) in expressions where the standard type is either signed or unsigned int.

What exactly is meant by expression?
For example if I have the following code:
Code:
uint_8 foo = (((uint_8)(900000Lu / 5000Lu)) - ((uint_8)(600000Lu / 5000Lu))) - 1u;
Is the complete part "(((uint_8)(900000Lu / 5000Lu)) - ((uint_8)(600000Lu / 5000Lu))) - 1u" to be treated as exact one expression or does it have to be split up into separate expressions step by step until it comes down to a + b to decide if the limitations from D.1 applies and paragraph D.7 takes effect.

In case I take the complete part from above as one single expression, for the code example the standard type of the complete expression would be evaluated to "(unsigned char - unsigned char) - unsigned int" which is promoted to "(signed int - signed int) - unsigned int" evaluated to "signed int - unsigned int" converted to "unsigned int - unsigned int" and finally results in "unsigned int".
Based on this result, which is unsigned int, the rules from D.7 needs to be applied.

However looking at the final expression "signed int - unsigned int" D.7 tells the following:
Quote:1. If the operands are both essentially signed then
[...]
2. Else if the operands are both essentially unsigned then
[...]
3. Else the essential types are the standard type
Since one is essentially signed while the other is essentially unsigned the result is the standard type which is unsigned int.

The numerical value value in this case would be 59u which would have the UTLR as unsigned char.
But since case 3 applies the final type is still unsigned int and therefore an assignment to uint_8 type variable is prohibited because of Rule 10.3 "The value of an expression shall not be assigned to an object with a narrower essential type [...]".


Looking at this on a different way and evaluate each sub expression separately by use of the essential type model I come to a different result.

(((uint_8)(900000Lu / 5000Lu)) - ((uint_8)(600000Lu / 5000Lu))) -1u;

(900000Lu / 5000Lu): both types are unsigned long int and therefore also the result will be unsigned long int. D.7 does not apply because of D.1.
=> 180Lu
result of the cast to ((uint_8)(180Lu)) is the standard type as casts are not specified in D.7 giving the result at unsigned char 180u.
For (600000Lu / 5000Lu) it is the same result as unsigned long, cast afterwards to unsigned char 120u.
The next expression is then "unsigned char 180u - unsigned char 120u". The result of this is signed int and therefore D.7 applies.
Quote:"2. Else if the operands are both essentially unsigned"
"2.1 If the expression is an integer constant expression the essential type of the result is the UTLR of the result."
This gives the result as 60u which has the UTLR of unsigned char.
Now "unsinged char 60u - unsigned int 1u" will be promoted to "signed int - unsigned int" and converted to "unsinged int - unsigned int" returning an unsigned int. Therefore D.7 applies and the result will be 59u which has the UTLR of unsigned char.
Based on this an assignment to uint_8 type variable is allowed.

Now my question is, which of these two approaches is the right one?

Print this item

  rule 13.2: are const volatile variables volatile or not?
Posted by: ggoulas - 22-09-2017, 02:05 PM - Forum: 8.13 Side effects - Replies (1)

Hi,

Quick question about rule 13.2:
the following variable:

const volatile uint8_t myvar = 0;

should it be considered as volatile or non-volatile in the context of rule 13.2 ?

thank you.

Print this item

  Essential type of integer constant expression of rank greater than unsigned int; interaction with addition to char
Posted by: abgs - 19-09-2017, 04:14 PM - Forum: 8.10 The essential type model - Replies (3)

Section D.6 says "If the standard type of an integer constant is unsigned int then its essential type is the UTLR." Then:

- The essential type of the integer literal 5U is unsigned char because the standard type is unsigned int and unsigned char is the smallest unsigned type capable of representing the value 5.

- The essential type of the integer literal 5UL is unsigned long because the standard type of the integer constant is not unsigned int and so the rule under the heading "Integer constants" has no effect.

Section D.7 describes the essential type of "Operations subject to the usual arithmetic conversions". Specifically, it says that "if the operands are both essentially unsigned then ... If the expression is an integer constant expression then the essential type of the result is the UTLR of the result", where "UTLR" is defined in D.3 as "the unsigned type having the lowest rank required to represent the value of a particular integer constant expression or the maximum value of a bit-field." Note in particular the absence of any restriction based on the standard type, unlike in the rule for literals. Then:

- The essential type of the integer constant expression 5U*5U is unsigned char because it is the unsigned type of lowest rank capable of representing the value 25.

- The essential type of the integer constant expression 5UL*5UL is also unsigned char because it is the unsigned type of lowest rank capable of representing the value 25.

The last conclusion regarding 5UL*5UL is complicated by the seemingly contradictory observation made in D.1 that "The essential type of an expression only differs from the standard C type (standard type) in expressions where the standard type is either signed int or unsigned int." while the standard type of this expression is unsigned long. If this passive statement is taken as a restriction on all other rules determining essential type (despite this not being stated) then there would be several strange effects:

- The essential type of the integer constant expression (uint32_t)(5U*5U) would differ depending on whether the typedef uint32_t is defined as "unsigned int" or "unsigned long", even if both are unsigned 32-bit integer types.

- The rules for the essential type of a bit-field in D.4 would no longer apply to bit-fields of type "unsigned long" if supported by the implementation, despite being explicitly permitted by rule 6.1.

- The explicit restriction that the essential type of an integer constant of unsigned type is only the UTLR when standard type is unsigned int in D.6 would be redundant.

- The essential type of the expression 'c'+1UL is specified to be char in D.2, but the standard type is not int nor unsigned int.

So my questions are:

- Is the essential type of 5U unsigned char?
- Is the essential type of 5UL unsigned long?
- Is the essential type of 5U*5U unsigned char?
- Is the essential type of 5UL*5UL unsigned char or unsigned long?
- Does the essential type of (uint32_t)(5U*5U) depend on whether uint32_t is defined as unsigned int or unsigned long if both are 32-bit unsigned integer types?
- Is the essential type of an expression referring to the value of a bit-field implemented using unsigned long in a C99 compiler that allows this the UTLR for the maximum value of the bitfield, or unsigned long?
- Is this sentence in D.1 intended to have any normative effect, and if so what is it and what is its scope? "The essential type of an expression only differs from the standard C type (standard type) in expressions where the standard type is either signed int or unsigned int."
- If the preceding phrase from D.1 does have a normative effect, is the reference to the specific standard type rather than merely the signedness in the phrase "If the standard type of an integer constant is unsigned int" in D.6 redundant?
- Is the essential type of the expression 'c'+1UL char as stated in D.2, or unsigned long if essential types cannot differ from standard types when the standard type is not signed/unsigned int as noted in D.1?

Print this item

  Constant expressions and cvalues
Posted by: abgs - 11-09-2017, 08:05 PM - Forum: 6.5 Expressions (C++) - Replies (1)

The description of cvalue expressions in section 6 uses the phrase "constant integral expressions" while citing the C++ standard section on constant expressions which does not contain the quoted phrase. Is "constant integral expressions" intended to say "integral constant expression", or does "constant integral expression" refer to a distinct concept?

Below, under the heading "Constant expressions", rules for "a constant expression" are defined in terms of the value of an integer literal. Not all "constant expressions" are integer values, e.g. the address-of operator can produce a "constant expression" of pointer type (but is not an "integral constant expression"), and it does not make sense to speak an integer literal having a pointer value. Is the use of unqualified "constant expression" here intended to have some missing "integral" qualification, or to continue referring to the "constant integral expressions" used earlier?

"Constant expressions" involving floating point arithmetic are not considered "integral constant expressions" but are "arithmetic constant expressions" (whereas "integral constant expressions" may contain floating literals if they are immediately cast to an integer type). Is an "arithmetic constant expression" that is not an "integral constant expression" considered a "constant integral expression" for the purposes of determining whether an expression is or is not a cvalue? Is an "arithmetic constant expression" considered a "constant expression" [presumably with a missing "integral" somewhere"] for the purposes of the "Constant expressions" heading even though it is not an "integral constant expression"?

Print this item

  int vs long when sizes are identical and issue with int32_t (from rule 6.3) in rule 10.1 example
Posted by: abgs - 11-09-2017, 06:14 PM - Forum: 6.10 Arithmetic Type Conversions - Replies (1)

Rule 10.1 contains the following example:

Code:
s32a = s16a + (int32_t)20000; /* compliant */
Rule 6.3 suggests this definition of int32_t:
Code:
typedef signed int int32_t;
The addition expression is a complex expression per 6.10.5.
The underlying type of s16a is int16_t.
The underlying type of (int32_t)20000 is int16_t because this is an integral constant expression and the "actual type" is int per 6.10.4:
Quote:If the actual type of the expression is (signed) int, the underlying type is defined to be the smallest signed integer type which is capable of representing its value.

The underlying type of the sum is then int16_t (not int32_t as the example seems to assume).
int16_t is being assigned to int32_t which requires a conversion to change the underlying type, but this is a violation of rule 10.1 because the sum is a complex expression. Thus the example appears not to be compliant.

Is this example incorrect when int32_t is int?
It appears that the behavior would be different if int32_t were long because the integral constant expression rule would not apply, is this intentional? How should this potential difference in the definition be handled?
If int and long are the same size, does conversion between int and long violate rule 10.1 because it only allows conversions to wider types and not to types of the same size?

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,207
» Latest member: MLBstubs
» Forum threads: 1,017
» Forum posts: 2,796

Full Statistics

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

Latest Threads
Rule 7.0.5, example non-c...
Forum: 4.7 Standard conversions
Last Post: cgpzs
17-04-2025, 12:10 PM
» Replies: 0
» Views: 163
A3-3-2 Contradictory exam...
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
31-03-2025, 09:30 AM
» Replies: 2
» Views: 292
16.6.1 clarification
Forum: 4.16 Overloading
Last Post: cgpzs
31-03-2025, 09:29 AM
» Replies: 2
» Views: 276
Rule 9.3.1 - iteration st...
Forum: 4.9 Statements
Last Post: misra cpp
28-03-2025, 01:17 PM
» Replies: 1
» Views: 183
Rule 8.2.8 - why aren't a...
Forum: 4.8 Expressions
Last Post: misra cpp
28-03-2025, 01:05 PM
» Replies: 1
» Views: 204
Typo in Appendix C of MIS...
Forum: 8.10 The essential type model
Last Post: Yordan Naydenov
17-03-2025, 02:58 PM
» Replies: 0
» Views: 161
Adopted modal expressions...
Forum: General Questions
Last Post: Yordan Naydenov
17-03-2025, 09:01 AM
» Replies: 0
» Views: 251
Roadmap to c23 support
Forum: General Questions
Last Post: ACHart
28-02-2025, 03:23 PM
» Replies: 0
» Views: 208
Rule 6.2.1 weak linkage
Forum: 4.6 Basic concepts
Last Post: misra cpp
28-02-2025, 01:04 PM
» Replies: 1
» Views: 264
A8-4-5: Should have an ex...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
21-02-2025, 12:58 PM
» Replies: 3
» Views: 683