From 814195c277cb4fb1b64b25775c65acd1a4630d09 Mon Sep 17 00:00:00 2001 From: Neal Gafter Date: Thu, 3 May 2018 21:30:19 -0400 Subject: [PATCH] Document representation of boolean values (#26609) Fixes #24652 --- docs/compilers/Boolean Representation.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docs/compilers/Boolean Representation.md diff --git a/docs/compilers/Boolean Representation.md b/docs/compilers/Boolean Representation.md new file mode 100644 index 00000000000..c4d0c594604 --- /dev/null +++ b/docs/compilers/Boolean Representation.md @@ -0,0 +1,6 @@ +Representation of Boolean Values +================================ + +The C# and VB compilers represent `true` (`True`) and `false` (`False`) `bool` (`Boolean`) values with the single byte values `1` and `0`, respectively, and assume that any boolean values that they are working with are restricted to being represented by these two underlying values. The ECMA 335 CLI specification permits a "true" boolean value to be represented by any nonzero value. If you use boolean values that have an underlying representation other than `0` or `1`, you can get unexpected results. This can occur in `unsafe` code in C#, or by interoperating with a language that permits other values. To avoid these unexpected results, it is the programmer's responsibility to normalize such incoming values. + +See also https://github.com/dotnet/roslyn/issues/24652 -- GitLab