Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
824 Views

#pragma pack doesn't work correctly

NIOSII, eclipse 

 

For a serial communication (TCP/UDP) I use pragma pack in order to simply copy incoming bytes from the interface and map a structure on it. 

Long time, it worked fine, but now i have the following problem. 

A function should read a value directly in such a packed structure value, but it is saving it one byte beside. On reading it takes the right place, so the value read is not the same as the value saved. 

While debugging I noticed that the pointer to the structure, (witch is hand over to the function) is impair, for example 0x00032543. 

 

Since I have several packed structures and instances from it, I tried to make the pointer pair by make a previously instanced structure one byte bigger. 

The result was in a pair pointer address for example 0x00032544, and it worked correctly. Is it a problem to hand over an impair pointer, so the pack directive doesn't really works? 

 

I'am wondering, why it was so long time no problem to work (with 12 such packed structures in my firmware), but now, suddenly it crashes. 

Has any one experience with# pragma pack(1) 

 

I also tried to close every directive with# pragma pack() without success. 

Should I now really rewrite all my section in the firmware with those structures?  

 

Many thanks in advance, Thomas
0 Kudos
1 Reply
Altera_Forum
Honored Contributor I
64 Views

Try using __attribute__((aligned(1))) instead. 

Although it really is best to align the data structures. 

To access misaligned data the compiler has to generate code to do byte memory cycles and shifts.
Reply