Skip to content

Commit 48b27c4

Browse files
authored
revise example metadata (#715)
1 parent 76e98ea commit 48b27c4

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

standard/unsafe-code.md

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ unsafe_statement
3939

4040
> *Example*: In the following code
4141
>
42-
> <!-- Example: {template:"standalone-lib", name:"UnsafeModifierOnStruct"} -->
42+
> <!-- Example: {template:"standalone-lib-without-using", name:"UnsafeModifierOnStruct"} -->
4343
> ```csharp
4444
> public unsafe struct Node
4545
> {
@@ -51,7 +51,7 @@ unsafe_statement
5151
>
5252
> the `unsafe` modifier specified in the struct declaration causes the entire textual extent of the struct declaration to become an unsafe context. Thus, it is possible to declare the `Left` and `Right` fields to be of a pointer type. The example above could also be written
5353
>
54-
> <!-- Example: {template:"standalone-lib", name:"UnsafeContexts2"} -->
54+
> <!-- Example: {template:"standalone-lib-without-using", name:"UnsafeContexts2"} -->
5555
> ```csharp
5656
> public struct Node
5757
> {
@@ -69,7 +69,7 @@ Other than establishing an unsafe context, thus permitting the use of pointer ty
6969
7070
> *Example*: In the following code
7171
>
72-
> <!-- Example: {template:"standalone-lib", name:"UnsafeContexts3", replaceEllipsis:true, ignoredWarnings:["CS0168"]} -->
72+
> <!-- Example: {template:"standalone-lib-without-using", name:"UnsafeContexts3", replaceEllipsis:true, ignoredWarnings:["CS0168"]} -->
7373
> ```csharp
7474
> public class A
7575
> {
@@ -94,7 +94,7 @@ Other than establishing an unsafe context, thus permitting the use of pointer ty
9494
>
9595
> The situation is slightly different when a pointer type is part of the method’s signature
9696
>
97-
> <!-- Example: {template:"standalone-lib", name:"UnsafeContexts4", replaceEllipsis:true} -->
97+
> <!-- Example: {template:"standalone-lib-without-using", name:"UnsafeContexts4", replaceEllipsis:true} -->
9898
> ```csharp
9999
> public unsafe class A
100100
> {
@@ -174,10 +174,8 @@ A *pointer_type* may be used as the type of a volatile field ([§14.5.4](classes
174174
175175
> *Note*: Although pointers can be passed as `ref` or `out` parameters, doing so can cause undefined behavior, since the pointer might well be set to point to a local variable that no longer exists when the called method returns, or the fixed object to which it used to point, is no longer fixed. For example:
176176
>
177-
> <!-- UndefinedExample: {template:"standalone-console", name:"PointerTypes1", replaceEllipsis:true, expectedOutput:["*px1 = 10","*px2 = 20"], expectedWarnings:["x","x"]} -->
177+
> <!-- Undefined$Example: {template:"standalone-console", name:"PointerTypes1", replaceEllipsis:true, expectedOutput:["*px1 = 10","*px2 = 20"], expectedWarnings:["x","x"]} -->
178178
> ```csharp
179-
> using System;
180-
>
181179
> class Test
182180
> {
183181
> static int value = 20;
@@ -214,7 +212,7 @@ A method can return a value of some type, and that type can be a pointer.
214212
215213
> *Example*: When given a pointer to a contiguous sequence of `int`s, that sequences element count, and some other `int` value, the following method returns the address of that value in that sequence, if a match occurs; otherwise it returns `null`:
216214
>
217-
> <!-- Example: {template:"standalone-console", name:"PointerTypes2", expectedWarnings:["CS8321"]} -->
215+
> <!-- Example: {template:"standalone-console-without-using", name:"PointerTypes2", expectedWarnings:["CS8321"]} -->
218216
> ```csharp
219217
> unsafe static int* Find(int* pi, int size, int value)
220218
> {
@@ -288,7 +286,7 @@ When one pointer type is converted to another, if the resulting pointer is not c
288286
289287
> *Example*: Consider the following case in which a variable having one type is accessed via a pointer to a different type:
290288
>
291-
> <!-- UndefinedExample: {template:"standalone-console", name:"PointerConversions1", expectedWarnings:["CS8321"]} -->
289+
> <!-- Undefined$Example: {template:"standalone-console-without-using", name:"PointerConversions1", expectedWarnings:["CS8321"]} -->
292290
> ```csharp
293291
> unsafe static void M()
294292
> {
@@ -307,9 +305,8 @@ When a pointer type is converted to a pointer to `byte`, the result points to th
307305
308306
> *Example*: The following method displays each of the eight bytes in a `double` as a hexadecimal value:
309307
>
310-
> <!-- ImplementationDefinedExample: {template:"standalone-console", name:"PointerConversions2", expectedOutput:["BA","FF","51","A2","90","6C","24","45"], expectedErrors:["x","x"]} -->
308+
> <!-- ImplementationDefined$Example: {template:"standalone-console", name:"PointerConversions2", expectedOutput:["BA","FF","51","A2","90","6C","24","45"], expectedErrors:["x","x"]} -->
311309
> ```csharp
312-
> using System;
313310
> class Test
314311
> {
315312
> static void Main()
@@ -420,9 +417,8 @@ A pointer member access of the form `P->I` is evaluated exactly as `(*P).I`. For
420417
> *Example*: In the following code
421418
>
422419
> <!-- Example: {template:"standalone-console", name:"PointerMemberAccess1", expectedOutput:["(10,20)"]} -->
420+
> <!-- Maintenance Note: A version of this type exists in additional-files as "PointStructWithToString.cs". As such, certain changes to this type definition might need to be reflected in that file, in which case, *all* examples using that file should be tested. -->
423421
> ```csharp
424-
> using System;
425-
>
426422
> struct Point
427423
> {
428424
> public int x;
@@ -448,7 +444,7 @@ A pointer member access of the form `P->I` is evaluated exactly as `(*P).I`. For
448444
>
449445
> the `->` operator is used to access fields and invoke a method of a struct through a pointer. Because the operation `P->I` is precisely equivalent to `(*P).I`, the `Main` method could equally well have been written:
450446
>
451-
> <!-- IncompleteExample: {template:"standalone-console", name:"PointerMemberAccess2", expectedOutput:["(10,20)"]} -->
447+
> <!-- Example: {template:"standalone-console", name:"PointerMemberAccess2", additionalFiles:["PointStructWithToString.cs"], expectedOutput:["(10,20)"]} -->
452448
> ```csharp
453449
> class Test
454450
> {
@@ -484,7 +480,7 @@ A pointer element access of the form `P[E]` is evaluated exactly as `*(P + E)`.
484480

485481
> *Example*: In the following code
486482
>
487-
> <!-- Example: {template:"standalone-console", name:"PointerElementAccess1"} -->
483+
> <!-- Example: {template:"standalone-console-without-using", name:"PointerElementAccess1"} -->
488484
> ```csharp
489485
> class Test
490486
> {
@@ -504,7 +500,7 @@ A pointer element access of the form `P[E]` is evaluated exactly as `*(P + E)`.
504500
>
505501
> a pointer element access is used to initialize the character buffer in a `for` loop. Because the operation `P[E]` is precisely equivalent to `*(P + E)`, the example could equally well have been written:
506502
>
507-
> <!-- Example: {template:"standalone-console", name:"PointerElementAccess2"} -->
503+
> <!-- Example: {template:"standalone-console-without-using", name:"PointerElementAccess2"} -->
508504
> ```csharp
509505
> class Test
510506
> {
@@ -548,8 +544,6 @@ The `&` operator does not require its argument to be definitely assigned, but fo
548544
>
549545
> <!-- Example: {template:"standalone-console", name:"Address-ofOperator", expectedOutput:["123"]} -->
550546
> ```csharp
551-
> using System;
552-
>
553547
> class Test
554548
> {
555549
> static void Main()
@@ -618,7 +612,6 @@ Given two expressions, `P` and `Q`, of a pointer type `T*`, the expression `P
618612
>
619613
> <!-- Example: {template:"standalone-console", name:"PointerArithmetic", inferOutput:true} -->
620614
> ```csharp
621-
> using System;
622615
> class Test
623616
> {
624617
> static void Main()
@@ -715,7 +708,7 @@ Fixed objects can cause fragmentation of the heap (because they can’t be moved
715708

716709
> *Example*: The example
717710
>
718-
> <!-- Example: {template:"standalone-console", name:"FixedStatement1"} -->
711+
> <!-- Example: {template:"standalone-console-without-using", name:"FixedStatement1"} -->
719712
> ```csharp
720713
> class Test
721714
> {
@@ -756,8 +749,6 @@ Within a `fixed` statement that obtains a pointer `p` to an array instance `a`,
756749
>
757750
> <!-- Example: {template:"standalone-console", name:"FixedStatement2", inferOutput:true} -->
758751
> ```csharp
759-
> using System;
760-
>
761752
> class Test
762753
> {
763754
> static void Main()
@@ -806,7 +797,7 @@ Within a `fixed` statement that obtains a pointer `p` to an array instance `a`,
806797
807798
> *Example*: In the following code
808799
>
809-
> <!-- Example: {template:"standalone-console", name:"FixedStatement3"} -->
800+
> <!-- Example: {template:"standalone-console-without-using", name:"FixedStatement3"} -->
810801
> ```csharp
811802
> class Test
812803
> {
@@ -927,7 +918,7 @@ A fixed-size buffer declaration that declares multiple fixed-size buffers is equ
927918

928919
> *Example*:
929920
>
930-
> <!-- Example: {template:"standalone-lib", name:"Fixed-sizeBuffers1"} -->
921+
> <!-- Example: {template:"standalone-lib-without-using", name:"Fixed-sizeBuffers1"} -->
931922
> ```csharp
932923
> unsafe struct A
933924
> {
@@ -937,7 +928,7 @@ A fixed-size buffer declaration that declares multiple fixed-size buffers is equ
937928
>
938929
> is equivalent to
939930
>
940-
> <!-- Example: {template:"standalone-lib", name:"Fixed-sizeBuffers2"} -->
931+
> <!-- Example: {template:"standalone-lib-without-using", name:"Fixed-sizeBuffers2"} -->
941932
> ```csharp
942933
> unsafe struct A
943934
> {
@@ -968,7 +959,7 @@ The subsequent elements of the fixed-size buffer can be accessed using pointer o
968959
969960
> *Example*: The following declares and uses a struct with a fixed-size buffer member.
970961
>
971-
> <!-- Example: {template:"standalone-console", name:"Fixed-sizeBuffersInExpressions"} -->
962+
> <!-- Example: {template:"standalone-console-without-using", name:"Fixed-sizeBuffersInExpressions"} -->
972963
> ```csharp
973964
> unsafe struct Font
974965
> {
@@ -1042,8 +1033,6 @@ All stack-allocated memory blocks created during the execution of a function mem
10421033
>
10431034
> <!-- Example: {template:"standalone-console", name:"StackAllocation", expectedOutput:["12345","-999"]} -->
10441035
> ```csharp
1045-
> using System;
1046-
>
10471036
> class Test
10481037
> {
10491038
> static string IntToString(int value)

0 commit comments

Comments
 (0)