Skip to content

Commit

Permalink
device_mmio: Fixed initialization of anonymous union on legacy compilers
Browse files Browse the repository at this point in the history
An anonymous union is a feature of the C language which allows a union
declared within a struct to be declared without a name:

    struct foo {
        union {
            int a;
            char b;
        };
    };

A struct containing an anonymous union may be initialized in either of the
following ways:

    /* Form A */
    struct foo test = {
        .a = 1234
    };

    /* Form B */
    struct foo test2 = {
        { .a = 1234 }
    };

Before the release of C11 (which became available in GCC 4.7.1), anonymous
unions were only supported by GNU extensions to the C language: GNU89 or
GNU99.

Support for Form A of anonymous union initialization was added in GCC
4.6.1. Older version only support Form B of the above example.

This patch improves compatiblity with legacy versions of GCC by converting
an instance of anonymous struct initialization from Form A to Form B.

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
  • Loading branch information
jhol committed Feb 3, 2025
1 parent 25ff621 commit c5ad90c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/zephyr/sys/device_mmio.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ struct z_device_mmio_rom {
* @param node_id DTS node_id
*/
#define DEVICE_MMIO_ROM_INIT(node_id) \
._mmio = Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
{ ._mmio = Z_DEVICE_MMIO_ROM_INITIALIZER(node_id) }

/**
* @def DEVICE_MMIO_MAP(device, flags)
Expand Down

0 comments on commit c5ad90c

Please sign in to comment.