Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clarification of Composite Expressions and casts
#1
In the example below, is the cast to uint32 in the statement in which r2 is assigned a violation of Rule 10.8?

Code:
typedef unsigned short uint16;
typedef unsigned int uint32;

void func(uint16 a, uint16 b) {
    uint32 r1;
    uint32 r2;
    r1 = (uint32) (a - b); // Violation of 10.8
    r2 = (uint32) (uint16) (a - b); // Violation of 10.8?
}

There do not seem to be any examples that specifically comment on this case but the wording of the definition of 'composite expression' introduces room for uncertainty. In particular, the part that says a composite expression
is the 'direct result of a composite operator'. What is the significance of 'direct' in the definition? Does (a - b) lose it's status as a composite expression after being cast to uint16 due to no longer being a 'direct result' of the composite operator? Or does 'direct' refer to something else? Finally, if this example is a violation of 10.8, is there a suggested means to avoid a violation without introducing a temporary variable?
<t></t>
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)