This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C28x [Integral promotion]

Hi!

I am dealing with TMS320C28x and wonder,

if anybody can provide the integral promotion rules for this target.

Thanks in advance,

Alexander

  • Alexander,

    The quick answer is the compiler follows the C Standard: ANSI X3.159-1989 (C89).  Is there something more specific you are looking for?

    PS - moving this to the compiler forum

  • Lori,


    thanks for your answer.

    To be honest, the hint to the standard is not helpful, because it tells you something about ranks which are

    dependend on the manufacturer. What is helpful: The standard says integer promotion. The literature says perhaps

    by mistake integral promotion.

    What I really want to know:

    When I have defined a variable

    unsigned long int ulA;

    and a variable int iB;

    then what happens implicitly having this statement when compiling:

    ulA = iB;

    Which steps does the compiler do to finally pass the value of iB to ulA on the platform TMS320C28x.

    Is it the same as

    ulA = (unsigned long) (long) iB; ?

    Is there a list which tells you when you assign iB to ulA, which implicit conversions are performed in which order?

    Thanks in advance for your help,

    Alexander Badura


  • Alexander Badura said:

    To be honest, the hint to the standard is not helpful, because it tells you something about ranks which are dependend on the manufacturer. What is helpful: The standard says integer promotion. The literature says perhaps by mistake integral promotion.

    What I really want to know:
    When I have defined a variable

    unsigned long int ulA;
    int iB;

    then what happens implicitly having this statement when compiling:

    ulA = iB;

    Which steps does the compiler do to finally pass the value of iB to ulA on the platform TMS320C28x.

    Is it the same as

    ulA = (unsigned long) (long) iB;

    ?

    Is there a list which tells you when you assign iB to ulA, which implicit conversions are performed in which order?

    For the integer types specified in the standard, the integer ranks are explicitly ordered and may not be altered by the implementation.  However, the ranks by themselves are not enough to figure out how integer values will be converted; you also need to know the sign of the source and destination types, and the relative size.

    The first case directly assigns a variable of one type to a variable of another type, which requires an implicit type conversion. This behaves exactly as if you had written:

    ulA = (unsigned long)iB;

    There are no intermediate steps; the value is converted directly from a int to an unsigned long.

    When converting from int to unsigned long for C28x (where int has fewer bits than unsigned long), the value of the result is computed modulo the maximum unsigned long value. You can view this as if the int value's sign bit were first extended out to the same number of bits as in the unsigned long. This computes the same value as would be computed with the expression

    ulA = (unsigned long) (long) iB;

    However, both casts are superfluous. This is as required by the standard.  The only thing that is implementation-defined in this example is the size of the integer types.  The important thing to know for this example is that on C28x, "int" is 16 bits and "unsigned long" is 32 bits.