dotnet / dotnet/docs

Types missing from "Default rules for marshalling common types" table

Open
#39,872 1 comment 1 reaction 0 assignees View on GitHub
:watch: Not Triaged dotnet-fundamentals/svc
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
19h 10m
Merged PRs (30d)
268

Description

### Type of issue

Missing information

### Description

1. The [Default rules for marshalling common types](https://learn.microsoft.com/en-us/dotnet/standard/native-interop/disabled-marshalling#default-rules-for-marshalling-common-types) table does not contain any floating point types at all. Types such as `double` are blittable and should be included in the table, no?
2. The table also does not mention enum types. It would be good to include them in the table for completeness.
3. The `C# keyword` for `System.Boolean` is omitted. Why isn't it shown as `bool`?
4. Also, `bool` wasn't a native type until C99, so it would be good to clarify that the "native type" for `bool` is the one referred to by C99; or if not, what exactly it is referring to.
5. The [`UnmanagedType.I1`](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.unmanagedtype?view=net-8.0#fields) enum has the following docstring: `A 1-byte signed integer. You can use this member to transform a Boolean value into a 1-byte, C-style bool (true = 1, false = 0).` According to the [default rules](https://learn.microsoft.com/en-us/dotnet/standard/native-interop/disabled-marshalling#default-rules-for-marshalling-common-types), a 1-byte signed integer is mapped to `sbyte` in C# and `int8_t` in native code. `bool` and `int8_t` are different types in C and I don't think that they are guaranteed to be interchangeable at the ABI level. Is the docstring suggesting that they are? Either way, it should be made more clear which native type must be used when marshalling C# `bool` as `UnmanagedType.I1` with runtime marshalling disabled.

### Page URL

https://learn.microsoft.com/en-us/dotnet/standard/native-interop/disabled-marshalling

### Content source URL

https://github.com/dotnet/docs/blob/main/docs/standard/native-interop/disabled-marshalling.md

### Document Version Independent Id

bdd8887a-c540-9642-f04c-2da4355ddd3a

### Article author

@jkoritzinsky

### Metadata

* ID: 9b4dda51-794d-ff7f-2d9e-5440de279522
* Service: **dotnet-fundamentals**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.