Change in libosmocore[master]: add/clean big-endian packed structs (struct_endianess.py)

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Mon Nov 19 16:09:52 UTC 2018


Neels Hofmeyr has posted comments on this change. ( https://gerrit.osmocom.org/11787 )

Change subject: add/clean big-endian packed structs (struct_endianess.py)
......................................................................


Patch Set 3:

(2 comments)

https://gerrit.osmocom.org/#/c/11787/2/include/osmocom/gprs/protocol/gsm_04_60.h
File include/osmocom/gprs/protocol/gsm_04_60.h:

https://gerrit.osmocom.org/#/c/11787/2/include/osmocom/gprs/protocol/gsm_04_60.h@33
PS2, Line 33: 	uint8_t tfi_hi:2, cv:4, si:1, r:1;
> Please change the script to add lines/formatting like in the little endian case.
that's "impossible" since the order is reversed. Doing it the tivial way it usually is done so far with whitespace carried along in the regexes, it would end up as:

    uint8_t                tfi_hi:8;
                    cv:4,
                    si:1,
     r:1,

(sic)

and I'm positively not going to spend time on that: it would involve interpreting indenting levels and open a whole nother chapter of pseudo intelligence.

I actually also prefer the packed output in the big-endian section, so no matter what formatting the original author invented, the big-endian part is "one line per byte" and more compact; whitespace changes then (mostly) don't affect the big-endian part. To read the struct for human understanding, just read above.


https://gerrit.osmocom.org/#/c/11787/2/include/osmocom/gsm/protocol/gsm_03_41.h
File include/osmocom/gsm/protocol/gsm_03_41.h:

https://gerrit.osmocom.org/#/c/11787/2/include/osmocom/gsm/protocol/gsm_03_41.h@36
PS2, Line 36: 		uint8_t language:4;
> Be careful here!! […]
no, the struct is packed. They are both a single byte. If you want to have ignored bits, you need to add 'padding' members. (but you had me for a second there)

try this:

    cat > /tmp/x.c <<END
    struct foo {
            unsigned int a:4;
            unsigned int b:4;
    } __attribute__((packed));
    int main(void)
    {
            return sizeof(struct foo);
    }
    END
    make -C /tmp x
    /tmp/x; echo $?

prints 1, i.e. struct foo is one byte.



-- 
To view, visit https://gerrit.osmocom.org/11787
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: Ia0b99d76932aeb03e93bd0c62d3bf025dec5f9d2
Gerrit-Change-Number: 11787
Gerrit-PatchSet: 3
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Comment-Date: Mon, 19 Nov 2018 16:09:52 +0000
Gerrit-HasComments: Yes
Gerrit-HasLabels: No
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181119/6d937807/attachment.htm>


More information about the gerrit-log mailing list