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.

Functionality fails due to data alignment issue.

I am noticing an issue where my codes functionality fails if I have the variables in the order below.


int x;
short y[18];
int z, a, b;

rearranging them as 

short y[18];

int x;

int z, a, b;

restores the pass functionality.

This little snippet is a part of a 150 file project.

Any suggestions of why this might be occuring ?

  • What CPU family does your device belong to?  What is the version of the compiler?  What are the build options?

    Thanks and regards,

    -George

  • c674x , ccs v5.3 and build options are none , no optimization is enabled, no debug symbols are enabled.
  • Please show all the build options exactly as the compiler sees them.

    Are these variables local to a function, global, inside a structure, or what?

    Thanks and regards,

    -George

  • George,

    These are local variable in a function.

    void getcode( int var1,int var2, short* var3, unsigned int var4, unsigned int var5)

    {

    int a ,int b;

    short c[18];

    int d , e, f;

    generate(a ,c);

    }

    The  compiler option used is just

    -Dc6748

    }

    The above functionality fails

    when  the local variables are declared as

    short c[18];

    int a ,int b;

    int d , e, f;

    or

    int a ,int b;

    int d , e, f;

    short c[18];

    or when -g, enable debug symbols, the functionality works as expected .

  • Does the generate() function take a pointer-to-short parameter for c? Is it expecting c to be anything other than an array of short? If it is treating c as a pointer to another type, for instance int, then the alignment could matter; the code would also be incorrect.