You are here

Optimization Array Issue | Cypress Semiconductor

Optimization Array Issue

Summary: 1 Reply, Latest post by Bob Marlowe on 25 Nov 2015 12:28 PM PST
Verified Answers: 1
Last post
Log in to post new comments.
tim_shannon_1496096's picture
1 post

Simple question I've looked at several different ways.  Can someone look over the code below and help me understand what I'm doing wrong?  I'm recieving the warning below and the Array is not functional.  It has to be something simple I'm not seeing.  Any help would be greatly appreciated.

"M0121: variable 'Input_Array' set but not used [-Wunused-but-set-variable]

int main()


int16 x;

uint8 Input_ADC;

uint8 ADC_Result =0;

uint8 Input_Array[16];

uint8 Input_Channel =0;

CyGlobalIntEnable; /* Enable global interrupts. */



M_4_Write(1); // enable external analog mux

while (x<3000) // delay before using

x++; //




Control_Reg_1_Write (Input_Channel);  // set channel external mux

while (x<3000) // Delay Before Conversion



while (Input_Channel<16) // scan routine


ADC_SAR_1_StartConvert(); // Start Conversion



ADC_Result = ADC_SAR_1_GetResult8();

Input_Array[Input_Channel] = ADC_Result;


Control_Reg_1_Write (Input_Channel);

while (x<3000) // Delay Before Conversion

x++; //




}// end for

}// end main


user_1377889's picture
9256 posts

Welcome in the Forum, Tim.

The warning is quite reasonable: You assign a value to Input_Array[] which is not a global variable (local to the function main) and you never use that value again. When not compiling with a strong optimization there will be no effect, just a warning. When compiling with optimization set to "Size" or "Speed" the assignment may be optimized-out.

Another pitfall: your delay-loop is quite undetermined. Better use CyDelay() or CyDelayus(), both documented in the "System Reference guide" (from Creator "Help"-menu.


Happy coding


Log in to post new comments.