#include #include #include int32_t* copyArray1(int32_t src[], int32_t size); void copyArray2(int32_t src[], int32_t dst[], int32_t size); int main(int argc, char **argv) { int32_t numbers[5] = {9, 8, 1, 9, 5}; int32_t copy1[5] = copyArray1(numbers, 5); // buggy int32_t copy2[5]; int32_t i; copyArray2(numbers, copy2, 5); // buggy for (i = 0; i < 5; i++) { printf("numbers[%d]: %d; copy1[%d]: %d; copy2[%d]: %d\n", i, numbers[i], i, copy1[i], i, copy2[i]); } return EXIT_SUCCESS; } int32_t* copyArray1(int32_t src[], int32_t size) { int32_t i, dst[size]; // OK in C99 for (i = 0; i < size; i++) { dst[i] = src[i]; } return dst; // no -- buggy } void copyArray2(int32_t src[], int32_t dst[], int32_t size) { int32_t i, copy[size]; // OK in C99 for (i = 0; i < size; i++) { copy[i] = src[i]; } dst = copy; // no -- still buggy }