A Type Conversion Question
From: Randy Yates (randy.yates_at_sonyericsson.com)
Date: 03/04/05
 Next message: Eric Sosman: "Re: A Type Conversion Question"
 Previous message: Dev: "Re: C Stack Corruption?"
 Next in thread: Eric Sosman: "Re: A Type Conversion Question"
 Reply: Eric Sosman: "Re: A Type Conversion Question"
 Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 04 Mar 2005 13:40:48 0500
Consider the following code:
#include "dsptypes.h"
/* definitions */
#define VECTOR_LENGTH 64
/* local variables */
/* local function prototypes */
/* function definitions */
int main(int margc, char **margv)
{
UINT16_T n;
INT16_T x[VECTOR_LENGTH];
INT16_T y[VECTOR_LENGTH];
INT32_T acc;
INT16_T result;
acc = 0;
for (n = 0; n < VECTOR_LENGTH; n++)
{
x[n] = n;
y[n] = VECTOR_LENGTH  n  1;
}
acc = 0;
for (n = 0; n < VECTOR_LENGTH; n++)
{
acc += x[n] * y[n];
}
result = (INT16_T)(acc >> 16);
return result;
}
What does ISO C say about how the conversions in the
acc += x[n] * y[n];
line are to be done? Specifically, is the multiply to be done with 16
bits, then the result promoted to 32 bits, or are x and y first to be
promoted to 32 bits before the multiply? Does the standard specify?
 Randy Yates Sony Ericsson Mobile Communications Research Triangle Park, NC, USA randy.yates@sonyericsson.com, 9194721124
 Next message: Eric Sosman: "Re: A Type Conversion Question"
 Previous message: Dev: "Re: C Stack Corruption?"
 Next in thread: Eric Sosman: "Re: A Type Conversion Question"
 Reply: Eric Sosman: "Re: A Type Conversion Question"
 Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
