Back to Basics Casting
Casting Or: how to subvert the type system Back to Basics Brian Ruth (he/him) brian.ruth@garmin.comAn Introduction struct region { int size; }; void init_region(char* backing_buffer, size_t for C++ casting 1. Different notation or different tasks 2. Easily recognized and searchable 3. Perform all operations that C casts can 4. Eliminate unintended errorsGoals for C++ casting 1. Different 3. Perform all operations that C casts can 4. Eliminate unintended errors 5. Make casting less enticingC++ casting operators* 1. static_cast 2. const_cast 3. dynamic_cast 4. reinterpret_cast *k0 码力 | 117 页 | 1.57 MB | 5 月前3The Zig Programming Language 0.4.0 Documentation
Sets Error Return Traces Implementation Details Optionals Optional Type null Optional Pointers Casting Implicit Casts Implicit Cast: Stricter Qualification Implicit Cast: Integer and Float Widening conversions are not possible. test.zig const assert = @import("std").debug.assert; test "pointer casting" { const bytes align(@alignOf(u32)) = []u8{ 0x12, 0x12, 0x12, 0x12 }; const u32_ptr = @ptrCast(*const 0x12121212); // Even this example is contrived - there are better ways to do the a // pointer casting. For example, using a slice narrowing cast: const u32_value = @bytesToSlice(u32, bytes[0..])[0];0 码力 | 207 页 | 5.29 MB | 1 年前3The Swift Programming Language
have additional capabilities that structures do not: For more information, see Inheritance, Type Casting, Initialization, and Automatic Reference Counting. N O T E Structures are always copied when they definition goes here 6 } Inheritance enables one class to inherit the characteristics of another. Type casting enables you to check and interpret the type of a class instance at runtime. Deinitializers enable buildingIdentifier method’s return value, and not the buildingIdentifier method itself. Type Casting Type casting is a way to check the type of an instance, and/or to treat that instance as if it is a different0 码力 | 525 页 | 4.68 MB | 1 年前3The Zig Programming Language 0.5.0 Documentation
Sets Error Return Traces Implementation Details Optionals Optional Type null Optional Pointers Casting Implicit Casts Implicit Cast: Stricter Qualification Implicit Cast: Integer and Float Widening conversions are not possible. test.zig const assert = @import("std").debug.assert; test "pointer casting" { const bytes align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12 }; const u32_ptr = @ptrCast(*const 0x12121212); // Even this example is contrived - there are better ways to do the a // pointer casting. For example, using a slice narrowing cast: const u32_value = @bytesToSlice(u32, bytes[0..])[0];0 码力 | 224 页 | 5.80 MB | 1 年前3The Swift Programming Language (Swift 5.7) - Apps Dissected
NSString. This means, if you import Foundation, you can access those NSString methods on String without casting. For more information about using String with Foundation and Cocoa, see Bridging Between String structures don’t have: Inheritance enables one class to inherit the characteristics of another. Type casting enables you to check and interpret the type of a class instance at runtime. Deinitializers enable allows more than one reference to a class instance. For more information, see Inheritance, Type Casting, Deinitialization, and Automatic Reference Counting. The additional capabilities that classes support0 码力 | 1040 页 | 10.90 MB | 1 年前3The Zig Programming Language 0.12.0 Documentation
preferable to @ptrCast if possible. test_pointer_casting.zig const std = @import("std"); const expect = std.testing.expect; test "pointer casting" { const bytes align(@alignOf(u32)) = [_]u8{ 0x12 // Even this example is contrived - there are better ways to do the above than // pointer casting. For example, using a slice narrowing cast: const u32_value = std.mem.bytesAsSlice(u32, bytes[0 Pointer.child == u32); } Shell $ zig test test_pointer_casting.zig 1/2 test_pointer_casting.test.pointer casting... OK 2/2 test_pointer_casting.test.pointer child type... OK All 2 tests passed. Alignment0 码力 | 241 页 | 7.37 MB | 1 年前3Firebird 2.5 Language Reference
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347 8.5. Type Casting Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .) ::= | [TYPE OF] domain | TYPE OF COLUMN relname.colname Casting to a Domain When you cast to a domain, any constraints declared for it are taken into account, i specified — casting to its base type — any domain constraints are ignored during the cast. If TYPE OF is used with a character type (CHAR/VARCHAR), the character set and collation are retained. Casting to TYPE 0 码力 | 521 页 | 2.30 MB | 1 年前3The Zig Programming Language 0.1.1 Documentation
value 0 is used as the null value. assert(@sizeOf(?&i32) == @sizeOf(&i32)); } test "pointer casting" { // To convert one pointer type to another, use @ptrCast. This is an unsafe // operation // Even this example is contrived - there are better ways to do the above than // pointer casting. For example, using a slice narrowing cast: const u32_value = ([]const u32)(bytes[0..])[0]; @ptrToInt and @intToPtr...OK Test 5/8 volatile...OK Test 6/8 nullable pointers...OK Test 7/8 pointer casting...OK Test 8/8 pointer child type...OK Alignment Each type has an alignment - a number of bytes0 码力 | 82 页 | 2.67 MB | 1 年前3The Zig Programming Language 0.11.0 Documentation
other conversions are not possible. test_pointer_casting.zig 1 const std = @import("std"); 2 const expect = std.testing.expect; 3 4 test "pointer casting" { 5 const bytes align(@alignOf(u32)) = [_]u8{ // Even this example is contrived - there are better ways to do the above than 10 // pointer casting. For example, using a slice narrowing cast: 11 const u32_value = std.mem.bytesAsSlice(u32, bytes[0 expect(@typeInfo(*u32).Pointer.child == u32); 21 } Shell $ zig test test_pointer_casting.zig 1/2 test.pointer casting... OK 2/2 test.pointer child type... OK All 2 tests passed. 13.2. Alignment Each0 码力 | 238 页 | 7.80 MB | 1 年前3The Zig Programming Language 0.2.0 Documentation
value 0 is used as the null value. assert(@sizeOf(?&i32) == @sizeOf(&i32)); } test "pointer casting" { // To convert one pointer type to another, use @ptrCast. This is an u // operation that 0x12121212); // Even this example is contrived - there are better ways to do the a // pointer casting. For example, using a slice narrowing cast: const u32_value = ([]const u32)(bytes[0..])[0]; @ptrToInt and @intToPtr...OK Test 5/8 volatile...OK Test 6/8 nullable pointers...OK Test 7/8 pointer casting...OK Test 8/8 pointer child type...OK Alignment Each type has an alignment - a number of bytes0 码力 | 117 页 | 2.84 MB | 1 年前3
共 574 条
- 1
- 2
- 3
- 4
- 5
- 6
- 58