mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
3.8 KiB
3.8 KiB
Special rules for distinct types
- Implicit conversion will happen from constant values that can be implicitly converted to the underlying type.
- Implicit conversion will happen to the underlying type if inline.
Special rules for vectors
- Implicit conversion will happen for non-vector numeric types, bools and pointers for init only.
- Explicit conversion is available in all other cases.
Special rules for bool conversion in conditionals
Types that may convert to a bool, will implicitly do so in a conditional.
Bool
Implicit conversion
None
Explicit conversion
- To float => 0.0 and 1.0
- To int => 0 and 1 (note, there is an argument for ~0 instead)
Int
Implicit conversion
- To float if simple expression
- To wider int if simple expression
Explicit conversion
- To bool/float/int always works
- To pointer if the int is pointer sized
- To enum (const will be range checked)
- To bitstruct if size matches
- To bool
Float
Implicit conversion
- To wider float if simple expression
Explicit conversion
- To int / float
- To bool
Non "void*" pointer
Implicit conversion
- To void*
- To
any - To slice if it is a pointer to a vector or array
- To an interface if the pointee implements the interface.
Explicit conversion
- To any pointer
- To any interface
- To an int size pointer
- To bool
"void*" pointer
Implicit conversion
- To any pointer
Explicit conversion
- To a pointer sized int.
- To bool
Slice
Implicit conversion
- To a pointer of the same base pointer. For constant strings the ichar and char are equivalent.
- To an array or vector of the same compile time known length if the array/vector conversion exists.
Explicit conversion
- To a pointer of the same structure.
- To a slice of the same structure.
- To an array of the vector of the same compile time known length if the explicit array/vector conversion exists.
Vector
Implicit conversion
- To a slice of the same type if the vector is constant.
- To another vector if the base type conversion is implicit
- To an array if the conversion would work if this was an array -> array conversion.
Explicit conversion
- To a slice of the same structural equivalent type if the vector is constant.
- To another vector if the base type conversion is valid.
- To an array if the conversion would work if this was an explicit array -> array conversion.
Array
Implicit conversion
- To a slice of the same type if the array is constant.
- To another array of the same length but with compatible types.
- To a vector if the conversion would work if this was an array -> array conversion.
Explicit conversion
- To a slice of the same structural equivalent type if the array is constant.
- To another array of the same length with structurally equivalent elements.
- To a vector if the conversion would work if this was an explicit array -> array conversion.
Bitstruct
Implicit conversion
None
Explicit conversion
- To the underlying type (integer or char array).
- To bool
Struct
Implicit conversion
- To inline member
Explicit conversion
None
Union
No conversions
"any"
Implicit conversion
- To
void*
Explicit conversion
- To any interface
- To any pointer
- To bool
Interface
Implicit conversion
- To
void* - To
any - To a parent interface
Explicit conversion
- To any other interface
- To any pointer
- To bool
Fault
Implicit conversion
- To
anyfault
Explicit conversion
- To a pointer sized int
- To bool
- To pointer
"anyfault"
Explicit conversion
- To a pointer sized int
- To bool
- To pointer
- To a
fault
"typeid"
Explicit conversion
- To a pointer size int
- To bool
- To pointer