Skip to content

Commit 6f831cf

Browse files
committed
feat: add QnA
1 parent cd88617 commit 6f831cf

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,44 @@ The macros are documented in the [header file](./smartptr.h)
5555
Copy [smartptr.h](./smartptr.h) into your project and `#include` it. That's it!
5656
Make sure you are using `gcc`, although other compilers might work too.
5757

58+
## QnA
59+
60+
#### **Q: I compile with gcc but use `clangd` for static analysis. Will this library break clang?**
61+
62+
A: You can easily allow the library to "do nothing" if it detects a non compatible compiler (like clang). \
63+
Thus clang (or any other compiler) analyzer will not break, and the gcc-compiled
64+
code will still work as intended. \
65+
To do this, open the header, and in the beginning, find
66+
```c
67+
// If you wish, you may enable for clang or any other non-gnu compiler to completely
68+
// ignore most* smartptr/defer statements. This can be useful for example if you
69+
// are using it as an LSP (like clangd).
70+
// * - non-special features like smartptr_func_ptr or smartptr will still work
71+
#if (!defined(__GNUC__) || defined(__clang__))
72+
73+
#if 0
74+
#define smartptr__setting_DO_NOTHING_SPECIAL
75+
#else
76+
#error "Unsupported compiler"
77+
#endif
78+
79+
#endif
80+
```
81+
Now, switch the `#if 0` to `#if 1`. \
82+
That's it!
83+
84+
#### **Q: I am writing in a non-libc environment and `stdlib`/`free` breaks my compiling/linking**
85+
86+
A: The easiest solution is to completely disable smartptr__free. Open the header and locate
87+
```c
88+
// If you do not wish to have a macro `smartptr` that calls free
89+
// (for example if you don't have libc, remove the following define)
90+
#define smartptr__setting_SUPPORT_FREE
91+
```
92+
somewhere in the beginning of the file. Now simply remove the `#define` line and
93+
you are good to go! \
94+
All of the other smartptr and defer features will work as intended.
95+
5896
## Contributing
5997
Contributions are welcome! Open an Issue or a PR with your questions/suggestions.
6098

0 commit comments

Comments
 (0)