At 11:39 10-05-05 +0200, you wrote:
>   Hi,       for your help about Re: Help about sizeof( struct ...) 
>MSP430-GCC        So, if i write the fowling function (Swap_TAB_UART), the 
>result is not good. the function lose len, ix values.    registers  !!!    
>  Kind Regards, Thln!       void Swap_TAB_UART(unsigned char ix, unsigned 
>char len)

>void Swap_TAB_UART(unsigned char ix, unsigned char len)
>{
>unsigned char i, tmp, l;
>  
>l = len/2;
>i = 0;
>do
>  {
>  tmp = TAB_UART[ix+i];
>  TAB_UART[ix+i] = TAB_UART[ix+len-i-1];
>  TAB_UART[ix+len-i-1] = tmp;
>  i++;
>  } while (i<l);
>}

Using 'complex' array indexes like these is asking for trouble (yes, I know
it should work...) I've seen commercial compilers choking on these sort of
constructions as well.
It is better to use a variable and pre-calculate the index like this:

void Swap_TAB_UART(unsigned char ix, unsigned char len)
{
unsigned char i, tmp, l;

short a,b;
  
l = len/2;
i = 0;
do
  {
  a=ix+i;
  b=ix+len-i-1; 
  tmp = TAB_UART[a];
  TAB_UART[a] = TAB_UART[b];
  TAB_UART[b] = tmp;
  i++;
  } while (i<l);
}


Nico Coesel


Reply via email to