Indexed Arrays Vs. Pointers; Trying Pointer And Indexed Styles - Analog Devices VISUALDSP++ 3.5 Manual

C/c++ compiler and library for adsp-219x processors
Hide thumbs Also See for VISUALDSP++ 3.5:
Table of Contents

Advertisement

General Guidelines
p = b;
// some use of p
Bad: uses of
because the latter may cause extra apparent aliases between the two uses.

Indexed Arrays vs. Pointers

C allows a program to access data from an array in two ways: either by
indexing from an invariant base pointer, or by incrementing a pointer.
These two versions of vector addition illustrate the two styles:
Style 1: using indexed arrays
void va_ind(const short a[], const short b[], short out[], int n) {
int i;
for (i = 0; i < n; ++i)
out[i] = a[i] + b[i];
}
Style 2: using pointers
void va_ptr(const short a[], const short b[], short out[], int n) {
int i;
short *pout = out;
const short *pa = a, *pb = b;
for (i = 0; i < n; ++i)
*pout++ = *pa++ + *pb++;
}

Trying Pointer and Indexed Styles

One might hope that the chosen style would not make any difference to
the generated code, but this is not always the case. Sometimes, one version
of an algorithm will generate better optimized code than the other, but it
is not always the same style that is better.
Tip: Try both pointer and index styles.
2-12
in different contexts may alias.
p
VisualDSP++ 3.5 C/C++ Compiler and Library Manual
for ADSP-219x DSPs

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the VISUALDSP++ 3.5 and is the answer not in the manual?

Questions and answers

Related Products for Analog Devices VISUALDSP++ 3.5

Table of Contents