TODOPIC

Microcontroladores PIC => Lenguaje C para microcontroladores PIC => Mensaje iniciado por: elgarbe en 03 de Junio de 2015, 19:45:34

Título: Asignar un array a otro array
Publicado por: elgarbe en 03 de Junio de 2015, 19:45:34
Buenas, tengo lo siguiente:

Código: [Seleccionar]

#define BufferSize 20000
int16_t InputBuffer[BufferSize];
int16_t OutputBuffer[BufferSize];

for(i=0;i<BufferSize;i++)
{
OutputBuffer[i]=InputBuffer[i];
}

Puedo directamente hacer esto:
Código: [Seleccionar]
OutputBuffer[]=InputBuffer[];

o algo por el estilo?

sds!
Título: Re: Asignar un array a otro array
Publicado por: juaperser1 en 03 de Junio de 2015, 20:16:19
hola elgarbe, no puedes hacer eso,

no se puede hacer directamente array1=array2 debido a que en este caso estas manipulando las direcciones (int*) y no los valores de los array. Para copiar los valores debes hacerlo como en lo primero que has posteado, o con alguna funcion de las diversas librerias que existen para arrays.

un saludo.
Título: Re: Asignar un array a otro array
Publicado por: RICHI777 en 04 de Junio de 2015, 13:16:25
Lo mas eficiente es hacer memcpy

Código: C
  1. memcpy( OutBuffer, InputBuffer, BufferSize );

Buenas, tengo lo siguiente:

Código: [Seleccionar]

#define BufferSize 20000
int16_t InputBuffer[BufferSize];
int16_t OutputBuffer[BufferSize];

for(i=0;i<BufferSize;i++)
{
OutputBuffer[i]=InputBuffer[i];
}

Puedo directamente hacer esto:
Código: [Seleccionar]
OutputBuffer[]=InputBuffer[];

o algo por el estilo?

sds!
Título: Re: Asignar un array a otro array
Publicado por: KILLERJC en 04 de Junio de 2015, 13:38:29
Por si las dudas, el memcpy de XC8 es

Código: C
  1. #include        <string.h>
  2. #if defined(__18CXX)
  3. #include        <htc.h>
  4. #endif
  5.  
  6. #ifdef _PIC16
  7. far void *
  8. memcpy(far void * d1, const void * s1, register size_t n)
  9. #else /*  _PIC16 */
  10. void *
  11. memcpy(void * d1, const void * s1, register size_t n)
  12. #endif /* _PIC16 */
  13. {
  14.  
  15. #ifdef _PIC16
  16.         register far char *     d;
  17. #else  /* _PIC16 */
  18.         register char *         d;
  19. #endif /* _PIC16 */
  20.         register const char *   s;
  21. #if defined(__18CXX)
  22.         volatile unsigned short long tmp = TBLPTR;
  23. #endif
  24.         s = s1;
  25.         d = d1;
  26.         while(n--)
  27.                 *d++ = *s++;
  28. #if defined(__18CXX)
  29.         TBLPTR = tmp;
  30. #endif
  31.         return d1;
  32. }