[SOLVED] Regression in definition of offsetof in Segger-supplied stddef.h

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] Regression in definition of offsetof in Segger-supplied stddef.h

    Hi.

    I have a project I've been developing in SES that uses protocol buffers generated using nanopb. What I've found is that, when I add the generated files to my project, it has several assertions that produce errors and warnings. As an example, one of the failing assertions is below. Building this code emits the error static_assert expression is not an integral constant expression and the warning cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression. Note that the assertion is not evaluating to false. Rather, the code inside is generating a compile-time error.

    C Source Code: static assertion demonstrating error.

    1. _Static_assert(((uint32_t) (((size_t) & (((SetVolume *) 0)->volume))) < ((uint32_t) 1 << 8)), "FIELDINFO_DOES_NOT_FIT_width1_field1");

    This assertion was created using the offsetof() macro. SetVolume is simply defined as

    C Source Code: SetVolume def.

    1. typedef struct _SetVolume {
    2. uint32_t volume;
    3. } SetVolume;
    I've been working with nanopb's maintainer to troubleshoot this issue. Essentially, what it seems to boil down to is a problem in Segger's definition of offsetof(). I'm using SES 6.20a, and offsetof() is defined in stddef.h as below:

    C Source Code: stddef.h Segger v5.70a

    1. #define offsetof(s,m) ((size_t)&(((s *)0)->m)) // Offset of m within s

    I also have version 5.70a installed, so I checked what stddef.h looks like in this version.

    C Source Code

    1. #if defined __GNUC__
    2. #define offsetof(s,m) __builtin_offsetof(s, m)
    3. #else
    4. #define offsetof(s,m) ((size_t)&(((s *)0)->m))
    5. #endif
    When using this definition, my project builds correctly. It looks like someone else has brought this issue up in the past, as per forum.segger.com/index.php/Thr…iler-error-from-offsetof/ . This thread is "solved", implying that the definition was updated at that time to use the __builtin_offsetof extension. So, the 6.20a removal of this definition appears to be a regression that breaks my code. Is there any reason Segger has removed support for gcc and clang's __builtin_offsetof extension?
  • Hello,

    Thank you for your inquiry.
    The issue should be fixed with the next Embedded Studio update.

    Sorry for any inconveniences caused.

    To get notified automatically when the new version is available you can subscribe here:
    segger.com/notification/subscribe.php?prodid=196

    Best regards,
    Nino
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.