utils icon indicating copy to clipboard operation
utils copied to clipboard

False triggering of recursive inclusion protection in list lib

Open dimmykar opened this issue 2 years ago • 2 comments

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)

dimmykar avatar Nov 01 '22 18:11 dimmykar

This is a good point and LIST_H could definitely be replaced with something more unique. I don't want to use #pragma once because it is not standard.

clnhlzmn avatar Nov 01 '22 19:11 clnhlzmn

In accordance with the name of the repository, you can use the UTILS_LIST_H option (and pattern UTILS_MODULE_H for all libraries of this repo), this option will already be more unique

dimmykar avatar Nov 01 '22 21:11 dimmykar