Skip to content

False triggering of recursive inclusion protection in list lib #4

@dimmykar

Description

@dimmykar

Hi! I liked your implementation of linked list without dynamic allocation, and I decided to try it in a fairly large STM32-based embedded project.

It was unexpected, when compiling, an error appeared when declaring a my list element that included a struct list_element structure:

typedef struct
{
    struct can_device *can_device;
    struct list_element elem;
} ONLINE_LIST_ELEMENT;

The error was pointing to struct list_element elem; and said the following:

"field elem has incomplete type"

In the implementation of struct list_element, everything was OK and I could not understand what the problem was. Finally, I saw a relatively simple defense against recursively including the list.h header:

#ifndef LIST_H
#define LIST_H

...

#endif // LIST_H

Replacing this construct with #pragma once, the compilation was finished successfully.

I don't even know where exactly I still have the LIST_H header included, but LIST_H is a very simple and common label.

It would be nice to replace it with something else, or use #pragma once (but this may not be available for some compilers, most likely outdated)

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