Allow fixed
to be omitted when taking a pointer to stack allocated memory?
#2249
Replies: 5 comments
-
How can it prove that a given
Would this require checking for an analyzing a |
Beta Was this translation helpful? Give feedback.
-
A user who knows a |
Beta Was this translation helpful? Give feedback.
-
@yaakov-h
It seems perfect plausible, from a design perspective, that span should also get special treatment here. |
Beta Was this translation helpful? Give feedback.
-
The compiler just emits a call to one of
IIRC the safety issue before C# 7.2 was due to user code using pointers, not due to the use of
Hmm, I didn't know that one, but it does make sense. So there's already some flow analysis going on? |
Beta Was this translation helpful? Give feedback.
-
Yep. My point with the first two wasn't that they weren't a span or anything, just that it's already treated as a special type to the language - this proposition wouldn't just add special behaviour for some random type, it is consistent with current behaviour. Given it already recognises them for the return restriction, it could allow |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
(I used
Microsoft (R) Visual C# Compiler version 3.0.19.6812 (231aeb8b)
)Where the compiler can prove that the pointer is to a stack allocated memory, can the language allow
fixed
to be omitted?BTW the error is
CS0029 Cannot implicitly convert type 'System.Span<uint>' to 'uint*'
but perhaps it could say..except in a fixed context
?Beta Was this translation helpful? Give feedback.
All reactions