How can i change struct padding byte on XC code?
It's possible on C code using using "__attribute__((packed))".
How can i change struct padding byte on XC code?
-
- Junior Member
- Posts: 6
- Joined: Thu Jun 20, 2013 6:07 am
-
- XCore Addict
- Posts: 133
- Joined: Tue Dec 15, 2009 10:23 pm
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
Yvo
-
- Junior Member
- Posts: 6
- Joined: Thu Jun 20, 2013 6:07 am
It struct is already made on other system. It wasn't considered for byte-align.
Preprocess syntax for byte-align of struct are?
Preprocess syntax for byte-align of struct are?
-
- XCore Addict
- Posts: 133
- Joined: Tue Dec 15, 2009 10:23 pm
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
This is (still) under the assumption that there isn't any support for this. Have you checked the compiler manuals?
-Yvo
-
- XCore Expert
- Posts: 844
- Joined: Sun Jul 11, 2010 1:31 am
I have checked the manuals, and I do not think XC supports packed structs.yzoer wrote:This is (still) under the assumption that there isn't any support for this. Have you checked the compiler manuals?
-
- XCore Expert
- Posts: 844
- Joined: Sun Jul 11, 2010 1:31 am
Never ever ever use the C structure layout for transfering data.kim5257 wrote:It struct is already made on other system. It wasn't considered for byte-align.
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 :-)
-
- Junior Member
- Posts: 6
- Joined: Thu Jun 20, 2013 6:07 am
Is that mean like that follow? For value input in the struct.segher wrote:Never ever ever use the C structure layout for transfering data.kim5257 wrote:It struct is already made on other system. It wasn't considered for byte-align.
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 :-)
Code: Select all
structVal.interger32 = (cData[3] << 24)|(cData[2] << 16)|(cData[1] << 8)|(cData[0]);
structVal.interger16 = (cData[5] << 8)|(cData[4]);
Code: Select all
structVal = (StructVal*)cData;