1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

doc: add a section documenting #preinclude (#17304)

This commit is contained in:
irishgreencitrus 2023-02-15 09:25:13 +00:00 committed by GitHub
parent d0a873ca02
commit 4691c5d637
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -196,6 +196,7 @@ by using any of the following commands in a terminal:
* [C Declarations](#c-declarations)
* [Export to shared library](#export-to-shared-library)
* [Translating C to V](#translating-c-to-v)
* [Working around C issues](#working-around-c-issues)
* [Other V Features](#other-v-features)
* [Inline assembly](#inline-assembly)
* [Hot code reloading](#hot-code-reloading)
@ -6424,6 +6425,37 @@ Translating it to V gives you several advantages:
- Cross-compilation becomes a lot easier. You don't have to worry about it at all.
- No more build flags and include files either.
### Working around C issues
In some cases, C interop can be extremely difficult.
One of these such cases is when headers conflict with each other.
For example, V needs to include the Windows header libraries in order for your V binaries to work
seamlessly across all platforms.
However, since the Windows header libraries use extremely generic names such as `Rectangle`,
this will cause a conflict if you wish to use C code that also has a name defined as `Rectangle`.
For very specific cases like this, we have `#preinclude`.
This will allow things to be configured before V adds in its built in libraries.
Example usage:
```v ignore
// This will include before built in libraries are used.
#preinclude "pre_include.h"
// This will include after built in libraries are used.
#include "include.h"
```
An example of what might be included in `pre_include.h`
can be [found here](https://github.com/irishgreencitrus/raylib.v/blob/main/include/pre.h)
This is an advanced feature, and will not be necessary
outside of very specific cases with C interop,
meaning it could cause more issues than it solves.
Consider it last resort!
## Other V Features
### Inline assembly