This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Struct assignment in c



Hi 

I am not sure if its the right forum to post this question. Sorry for that.

CCS version : 6.1.0.00104

Compiler : v6.4.3

I have two structs as shown below...

typedef struct _ABC_
{
 float a;
 float b;
 float c;
 }ABC;

 typedef struct _XYZ_1_
 {
  int a0;
  ABC abc1; 
 }XYZ1;

 typedef struct _XYZ_2
 {
  int a1;
  ABC abc2;
 }XYZ2;

I want to copy the struct ABC in the struct XYZ2 to the struct ABC defined as a member in struct XYZ1.

i know the most basic way as

void sampleFn(void){
 XYZ2 xyz2;
 XYZ1 xyz1;

/* This works fine */ xyz1.abc1.a = xyz2.abc2.a; xyz1.abc1.b = xyz2.abc2.c; xyz1.abc1.c = xyz2.abc2.c;

/* But this doesnt work */
xyz1.abc1 = xyz2.abc2;
}

Any help on this would be greatly appreciated.

  • Rambabu,

    I tried this on the ARM compiler and it worked. What compiler are you using?

    Also, how do you know its not working? If you are using System_printf() with floats, you need to add the extended System_printf formats in your .cfg file.

    System.extendedFormats = "%$S%$F%f";