diff --git a/categories/apis/index.html b/categories/apis/index.html index 18bfe26c..f7607476 100644 --- a/categories/apis/index.html +++ b/categories/apis/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/binding/index.html b/categories/binding/index.html index 51f41f48..ad280a89 100644 --- a/categories/binding/index.html +++ b/categories/binding/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/c/index.html b/categories/c/index.html index b4ba11fd..01e219de 100644 --- a/categories/c/index.html +++ b/categories/c/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/declaration/index.html b/categories/declaration/index.html index d08c1072..2b86fa80 100644 --- a/categories/declaration/index.html +++ b/categories/declaration/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/documentation/index.html b/categories/documentation/index.html index dd1a6107..f6d1dab4 100644 --- a/categories/documentation/index.html +++ b/categories/documentation/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/feature/index.html b/categories/feature/index.html index d2013767..4c72a360 100644 --- a/categories/feature/index.html +++ b/categories/feature/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/foreign/index.html b/categories/foreign/index.html index 5f0cd09a..b906dad0 100644 --- a/categories/foreign/index.html +++ b/categories/foreign/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/fun/index.html b/categories/fun/index.html index f943378e..2b58af38 100644 --- a/categories/fun/index.html +++ b/categories/fun/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/games/index.html b/categories/games/index.html index 02f35c41..098c78ae 100644 --- a/categories/games/index.html +++ b/categories/games/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/graphics/index.html b/categories/graphics/index.html index 6f874c9c..6bd9dd77 100644 --- a/categories/graphics/index.html +++ b/categories/graphics/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/handmade/index.html b/categories/handmade/index.html index 62756d67..2e506656 100644 --- a/categories/handmade/index.html +++ b/categories/handmade/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/index.html b/categories/index.html index e44d7eb5..3f30b63a 100644 --- a/categories/index.html +++ b/categories/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/newsletter/index.html b/categories/newsletter/index.html index 6287b2a8..22f5dbd6 100644 --- a/categories/newsletter/index.html +++ b/categories/newsletter/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/odin/index.html b/categories/odin/index.html index b0efb3d5..4a351372 100644 --- a/categories/odin/index.html +++ b/categories/odin/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/packages/index.html b/categories/packages/index.html index faf3e7a5..98e800b0 100644 --- a/categories/packages/index.html +++ b/categories/packages/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/python/index.html b/categories/python/index.html index f79977ca..498e412f 100644 --- a/categories/python/index.html +++ b/categories/python/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/reading/index.html b/categories/reading/index.html index cd40c9cc..c73e6e66 100644 --- a/categories/reading/index.html +++ b/categories/reading/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/showcase/index.html b/categories/showcase/index.html index 30f415ad..a3f14d2a 100644 --- a/categories/showcase/index.html +++ b/categories/showcase/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/spall/index.html b/categories/spall/index.html index 2b78f466..b319cc26 100644 --- a/categories/spall/index.html +++ b/categories/spall/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/streams/index.html b/categories/streams/index.html index 47f046fa..3df5da64 100644 --- a/categories/streams/index.html +++ b/categories/streams/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/syntax/index.html b/categories/syntax/index.html index 7f47f6a5..1c32c99e 100644 --- a/categories/syntax/index.html +++ b/categories/syntax/index.html @@ -12,7 +12,7 @@ - + diff --git a/categories/todool/index.html b/categories/todool/index.html index f506b72c..b9dff754 100644 --- a/categories/todool/index.html +++ b/categories/todool/index.html @@ -12,7 +12,7 @@ - + diff --git a/community/discord/index.html b/community/discord/index.html index 991cc5b9..cc85f7eb 100644 --- a/community/discord/index.html +++ b/community/discord/index.html @@ -11,7 +11,7 @@ - + diff --git a/community/how-you-can-help/index.html b/community/how-you-can-help/index.html index 68026254..e0664b7e 100644 --- a/community/how-you-can-help/index.html +++ b/community/how-you-can-help/index.html @@ -11,7 +11,7 @@ - + diff --git a/community/index.html b/community/index.html index 5fed098a..94081e80 100644 --- a/community/index.html +++ b/community/index.html @@ -11,7 +11,7 @@ - + diff --git a/docs/faq/index.html b/docs/faq/index.html index ae090679..027e4761 100644 --- a/docs/faq/index.html +++ b/docs/faq/index.html @@ -11,7 +11,7 @@ - + diff --git a/docs/index.html b/docs/index.html index 440bc5e4..ea45d226 100644 --- a/docs/index.html +++ b/docs/index.html @@ -11,7 +11,7 @@ - + diff --git a/docs/install/index.html b/docs/install/index.html index 37ee614f..0b9f32c6 100644 --- a/docs/install/index.html +++ b/docs/install/index.html @@ -11,7 +11,7 @@ - + diff --git a/docs/nightly/index.html b/docs/nightly/index.html index 1fd01590..13fa7a0a 100644 --- a/docs/nightly/index.html +++ b/docs/nightly/index.html @@ -11,7 +11,7 @@ - + diff --git a/docs/overview/index.html b/docs/overview/index.html index 76640106..b5eef5a8 100644 --- a/docs/overview/index.html +++ b/docs/overview/index.html @@ -11,7 +11,7 @@ - + @@ -699,7 +699,8 @@
However, transmute
does not require taking the address of the value in question, which may not be possible for many expressions.
In the Odin type system, certain expressions will have an “untyped” type. An untyped type can implicitly convert to a “typed” type.
-I :: 42 // untyped integer, will implicitly convert to int, uint and its sized variants
+I :: 42 // untyped integer, will implicitly convert to any numeric type (int, u32, f64, quaternion128 etc)
+F :: 1.37 // untyped float, will implicitly convert to any numeric type that can support fractional parts (f64, quaternion128 etc)
S :: "Hellope" // untyped string, will implicitly convert to string and cstring
B :: true // untyped boolean, will implicitly convert to bool, b8, b16, etc.
Auto cast operation #
@@ -1497,12 +1498,23 @@ Struct literals
Structs can be tagged with different memory layout and alignment requirements:
-struct #align 4 {...} // align to 4 bytes
+
Structs can be annotated with different memory layout and alignment requirements:
+struct #align(4) {...} // align to 4 bytes
struct #packed {...} // remove padding between fields
struct #raw_union {...} // all fields share the same offset (0). This is the same as C's union
-
Struct fields can be tagged with a string literal to attach meta-infomration which can be used with runtime-type information. Usually this is used to provide transactional information info on how a struct field is encoded to or decoded from another format, but you can store whatever you want within the string literal
+User :: struct {
+ flag: bool, // untagged field
+ age: int "custom whatever information",
+ name: string `json:"username" xml:"user-name" fmt:"q"`, // `core:reflect` layout
+}
+
Within Odin’s core library, the standard convention is to store a key
that denotes the package and then a subsequence "value"
. For example, json
keys are processed and used by core:encoding/json
package, fmt
keys are processed by core:fmt
.
If multiple information is to be passed in the "value"
, usually it is specified by separating it with a common (,
), e.g.
name: string `json:"username,omitempty",
+
n.b. Field tags also exist for bit_field
record types.
A union
in Odin is a discriminated union, also known as a tagged union or sum type. The zero value of a union is nil
.
Value :: union {
bool,
@@ -1567,7 +1579,7 @@ Struct literals
Unions also have the #align
tag, like structures:
union #align 4 {...} // align to 4 bytes
+union #align(4) {...} // align to 4 bytes
Maps #
A map
maps keys to values. The zero value of a map is nil
. A nil
map has no keys. The built-in make
proc returns an initialized map using the current context, and delete
can be used to delete a map.
m := make(map[string]int)
@@ -1633,6 +1645,21 @@ Procedure type
Bit Fields #
+A bit_field
is a record type in Odin that is akin to a bit-packed struct. Note: bit_field
is not equivalent to bit_set
as it has different semantics and use cases. A bit_field
’s field can be access using a do:
+Foo :: bit_field u16 { // backing type must be an integer or array of integers
+ x: i32 | 3, // signed integers will be signed extended on use
+ y: u16 | 2 + 3, // general expressions
+ z: My_Enum | foo.SOME_CONSTANT, // ability to define the bit-width elsewhere
+ w: bool | foo.SOME_CONSTANT > 10 ? 2 : 1,
+}
+
+v := Foo{}
+v.x = 4 // truncates the value to fit into 3 bits
+fmt.println(v.x) // accessing will convert `v.x` to an `i32` and do an appropriate sign extension
+
A bit_field
is different from a struct
in that you must specify the backing type. This backing type must be an integer or a fixed-length array of integers. This is useful if there needs to be a specific alignment or access pattern for the record.
+Foo :: bit_field u32 {...}
+Foo :: bit_field [4]u8 {...}
Calling conventions #
Odin supports the following calling conventions:
@@ -2867,10 +2894,10 @@ #packed
#<
struct #raw_union {u: u32, i: i32, f: f32}
#align
#
This tag can be applied to a struct
or union
. When #align
is passed an integer N
(as in #align N
), it specifies that the struct
will be aligned to N
bytes. The struct
’s fields will remain in source-order.
-Foo :: struct #align 4 {
+Foo :: struct #align(4) {
b: bool,
}
-Bar :: union #align 4 {
+Bar :: union #align(4) {
i32,
u8,
}
@@ -3336,7 +3363,8 @@ What to do if you get stuck Structs
- Unions
@@ -3350,7 +3378,8 @@
What to do if you get stuck Map Container Calls
-Procedure type
+ Procedure type
+Bit Fields
diff --git a/docs/spec/index.html b/docs/spec/index.html
index 406db37d..d384768a 100644
--- a/docs/spec/index.html
+++ b/docs/spec/index.html
@@ -11,7 +11,7 @@
-
+
diff --git a/index.html b/index.html
index 2a6b444f..0618d5e1 100644
--- a/index.html
+++ b/index.html
@@ -12,7 +12,7 @@
-
+
diff --git a/news/binding-to-c/index.html b/news/binding-to-c/index.html
index 03f66293..8ba95315 100644
--- a/news/binding-to-c/index.html
+++ b/news/binding-to-c/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/calling-odin-from-python/index.html b/news/calling-odin-from-python/index.html
index 3631a968..a0340100 100644
--- a/news/calling-odin-from-python/index.html
+++ b/news/calling-odin-from-python/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/declaration-syntax/index.html b/news/declaration-syntax/index.html
index bd2f7faf..682244ef 100644
--- a/news/declaration-syntax/index.html
+++ b/news/declaration-syntax/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/index.html b/news/index.html
index 231ef712..aa3829af 100644
--- a/news/index.html
+++ b/news/index.html
@@ -12,7 +12,7 @@
-
+
diff --git a/news/major-graphics-apis/index.html b/news/major-graphics-apis/index.html
index 8fbb04be..7e5096ea 100644
--- a/news/major-graphics-apis/index.html
+++ b/news/major-graphics-apis/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/new-package-documentation/index.html b/news/new-package-documentation/index.html
index 64492ccf..c6ee57d4 100644
--- a/news/new-package-documentation/index.html
+++ b/news/new-package-documentation/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/newsletter-2022-11/index.html b/news/newsletter-2022-11/index.html
index eeafebb7..e92a1f13 100644
--- a/news/newsletter-2022-11/index.html
+++ b/news/newsletter-2022-11/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/newsletter-2022-12/index.html b/news/newsletter-2022-12/index.html
index b77c15b7..f7679a34 100644
--- a/news/newsletter-2022-12/index.html
+++ b/news/newsletter-2022-12/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/newsletter-2023-04/index.html b/news/newsletter-2023-04/index.html
index a34fa142..9eb398bb 100644
--- a/news/newsletter-2023-04/index.html
+++ b/news/newsletter-2023-04/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/newsletter-2023-06/index.html b/news/newsletter-2023-06/index.html
index c0a250f0..774ab957 100644
--- a/news/newsletter-2023-06/index.html
+++ b/news/newsletter-2023-06/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/newsletter-2023-07/index.html b/news/newsletter-2023-07/index.html
index 94e32fbe..33fdb49e 100644
--- a/news/newsletter-2023-07/index.html
+++ b/news/newsletter-2023-07/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/newsletter-2023-08/index.html b/news/newsletter-2023-08/index.html
index 4fb7a3f3..95575811 100644
--- a/news/newsletter-2023-08/index.html
+++ b/news/newsletter-2023-08/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/newsletter-2023-09/index.html b/news/newsletter-2023-09/index.html
index 4632e428..7dde47ab 100644
--- a/news/newsletter-2023-09/index.html
+++ b/news/newsletter-2023-09/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/newsletter-2023-11/index.html b/news/newsletter-2023-11/index.html
index 7946ef5e..84df7b7d 100644
--- a/news/newsletter-2023-11/index.html
+++ b/news/newsletter-2023-11/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/newsletter-2023-12/index.html b/news/newsletter-2023-12/index.html
index a18c1233..1d581dcf 100644
--- a/news/newsletter-2023-12/index.html
+++ b/news/newsletter-2023-12/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/newsletter-2024-01/index.html b/news/newsletter-2024-01/index.html
index f2b70bb9..ac4dcd8e 100644
--- a/news/newsletter-2024-01/index.html
+++ b/news/newsletter-2024-01/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/newsletter-2024-02/index.html b/news/newsletter-2024-02/index.html
index 9f1519ff..1154ffb9 100644
--- a/news/newsletter-2024-02/index.html
+++ b/news/newsletter-2024-02/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/newsletter-2024-03/index.html b/news/newsletter-2024-03/index.html
index f2191ddb..73c6e5cc 100644
--- a/news/newsletter-2024-03/index.html
+++ b/news/newsletter-2024-03/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/newsletter-2024-04/index.html b/news/newsletter-2024-04/index.html
index 3ff81b38..46479e13 100644
--- a/news/newsletter-2024-04/index.html
+++ b/news/newsletter-2024-04/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/optional-semicolons/index.html b/news/optional-semicolons/index.html
index 452ee987..891e4a46 100644
--- a/news/optional-semicolons/index.html
+++ b/news/optional-semicolons/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/quine-in-odin/index.html b/news/quine-in-odin/index.html
index df891b57..a8cc084e 100644
--- a/news/quine-in-odin/index.html
+++ b/news/quine-in-odin/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/news/read-a-file-line-by-line/index.html b/news/read-a-file-line-by-line/index.html
index 7ae857b0..a1319d9c 100644
--- a/news/read-a-file-line-by-line/index.html
+++ b/news/read-a-file-line-by-line/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/showcase/cat_and_onion/index.html b/showcase/cat_and_onion/index.html
index 11a74e2d..739165a3 100644
--- a/showcase/cat_and_onion/index.html
+++ b/showcase/cat_and_onion/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/showcase/embergen/index.html b/showcase/embergen/index.html
index 683bef6c..ba15dd8d 100644
--- a/showcase/embergen/index.html
+++ b/showcase/embergen/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/showcase/index.html b/showcase/index.html
index 084d3736..a3bbcd02 100644
--- a/showcase/index.html
+++ b/showcase/index.html
@@ -12,7 +12,7 @@
-
+
diff --git a/showcase/ols/index.html b/showcase/ols/index.html
index 4778459d..b0deff36 100644
--- a/showcase/ols/index.html
+++ b/showcase/ols/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/showcase/solar_storm/index.html b/showcase/solar_storm/index.html
index a96c02b4..7a1eb065 100644
--- a/showcase/solar_storm/index.html
+++ b/showcase/solar_storm/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/showcase/spall/index.html b/showcase/spall/index.html
index ce423603..e04ef4fe 100644
--- a/showcase/spall/index.html
+++ b/showcase/spall/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/showcase/todool/index.html b/showcase/todool/index.html
index 8773c60e..2fc4d36b 100644
--- a/showcase/todool/index.html
+++ b/showcase/todool/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/tags/index.html b/tags/index.html
index 4520f073..a14d8f51 100644
--- a/tags/index.html
+++ b/tags/index.html
@@ -12,7 +12,7 @@
-
+
diff --git a/tags/quine/index.html b/tags/quine/index.html
index 84db934b..95c8d0cd 100644
--- a/tags/quine/index.html
+++ b/tags/quine/index.html
@@ -12,7 +12,7 @@
-
+