How can i change struct padding byte on XC code?

Technical questions regarding the XTC tools and programming with XMOS.
kim5257
Junior Member
Posts: 6
Joined: Thu Jun 20, 2013 6:07 am

How can i change struct padding byte on XC code?

Post by kim5257 »

How can i change struct padding byte on XC code?
It's possible on C code using using "__attribute__((packed))".


yzoer
XCore Addict
Posts: 133
Joined: Tue Dec 15, 2009 10:23 pm

Post by yzoer »

Not sure if there's an attribute for that. Barring that, you can always just add extra fields to your structure and pad it out manually..

Yvo
kim5257
Junior Member
Posts: 6
Joined: Thu Jun 20, 2013 6:07 am

Post by kim5257 »

It struct is already made on other system. It wasn't considered for byte-align.
Preprocess syntax for byte-align of struct are?
yzoer
XCore Addict
Posts: 133
Joined: Tue Dec 15, 2009 10:23 pm

Post by yzoer »

If you have the source, it shouldn't really matter unless their code accesses data without using the structure.

This is (still) under the assumption that there isn't any support for this. Have you checked the compiler manuals?

-Yvo
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

yzoer wrote:This is (still) under the assumption that there isn't any support for this. Have you checked the compiler manuals?
I have checked the manuals, and I do not think XC supports packed structs.
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

kim5257 wrote:It struct is already made on other system. It wasn't considered for byte-align.
Never ever ever use the C structure layout for transfering data.
Transfer data as a stream of bytes; do correct (un)serialising on
everything. That way, endianness does not matter, size of integer
types in C does not matter, struct layout does not matter.

Not doing this is not even premature "optimisation", it is just
laziness :-)
kim5257
Junior Member
Posts: 6
Joined: Thu Jun 20, 2013 6:07 am

Post by kim5257 »

segher wrote:
kim5257 wrote:It struct is already made on other system. It wasn't considered for byte-align.
Never ever ever use the C structure layout for transfering data.
Transfer data as a stream of bytes; do correct (un)serialising on
everything. That way, endianness does not matter, size of integer
types in C does not matter, struct layout does not matter.

Not doing this is not even premature "optimisation", it is just
laziness :-)
Is that mean like that follow? For value input in the struct.

Code: Select all

structVal.interger32 = (cData[3] << 24)|(cData[2] << 16)|(cData[1] << 8)|(cData[0]);
structVal.interger16 = (cData[5] << 8)|(cData[4]);
Normally i using code follow:

Code: Select all

structVal = (StructVal*)cData;