Skip to content

hma_allocator anonymous struct warning #2

@TobiPristupin

Description

@TobiPristupin

The definition of struct hma_allocator uses an anonymous struct.

typedef struct hma_allocator
{
  int (* allocate)(void *, size_t);
  void (* share)(void *, int);
  void (* deallocate)(void *, int);
  void (* copy_from)(void *, void *, size_t);
  void (* copy_to)(void *, void *, size_t);
  void (* copy)(void *, void *, size_t, struct hma_allocator *);
  void (* unmap)(struct hma_allocator *);
  void * data;   // Implementation specific stuff

  // ---Boundary between local memory and shared memory mapping occurs here---

  int shmem_id;
  union {   // Only allocators in same domain (same device) can use each other's memory
    struct //HERE! Anonymous struct
    {
      uint16_t device_type;
      uint16_t device_number;
    };
    uint32_t domain;
  };
  uint16_t strategy;
} hma_allocator_t;

This produced the following warning: warning: ISO C++ prohibits anonymous structs [-Wpedantic]

This can be fixed by naming the struct, and then refactoring all accesses to device_type and device_number to include the struct's name as a prefix.

I'm assuming all the references to those variables are inside of this project. If some external code accesses this struct and expects a certain naming scheme then this might be very hard to fix and it could be better to just add a compiler directive to skip the warning for this struct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions