Knowledge Base Article

Array Elements in Structures Do Not Copy Correctly

Description

C2H accelerators do not correctly copy array elements that are elements of structures.

In , the a and b elements of the structure copy correctly, but the buf element does not. After this assignment, struct_a equals {9, 8, {3, 3, 3, 3}}.

Array Elements of Structs
typedef struct my_struct { int a; int b; int buf[BUF_SIZE]; }MY_STRUCT; MY_STRUCT struct_a = {1, 2, {3, 3, 3, 3}}; MY_STRUCT struct_b = {9, 8, {7, 7, 7, 7}}; struct_a = struct_b;
Resolution

Copy the array elements explicitly, as shown in .

Copying Array Elements Explicitly
{ int i=0; do { struct_a.buf[i] = struct_b.buf[i]; i ; } while (i<LENGTH_OF_BUF_ELEMENT) }
Updated 2 months ago
Version 2.0
No CommentsBe the first to comment