Skip to content

Commit d8d9afd

Browse files
committed
odin procedure overloading
1 parent caf3012 commit d8d9afd

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

content/posts/odin-guide.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ ptr = raw_data(arr[:]) // get multi pointer to a slice of the array
220220
fmt.println(ptr, ptr[1], arr) // 0x7FFCBE9FE688 20 [10, 20, 30]
221221
```
222222

223-
basic rules for indexing and slicing for multi pointers:
223+
basic rules about what returns when indexing or slicing multi pointers:
224224

225225
```odin
226226
mptr: [^]T
@@ -281,6 +281,28 @@ i: i64 = 123
281281
f: f64 = transmute(f64)i
282282
```
283283

284+
## Function Overloading
285+
286+
Unlike in many other languages, operator overloading in Odin is explicit,
287+
the reason being that procedures can be nested within procedures and, as a result,
288+
determining which procedure should be used in the case of implicit overloading is complex,
289+
therefore explicit overloading makes more sense.
290+
291+
Here is an example of how to do function overloading:
292+
293+
```odin
294+
bool_to_string :: proc(b: bool) -> string {
295+
// convert bool to string
296+
}
297+
298+
int_to_string :: proc(i: int) -> string {
299+
// convert int to string
300+
}
301+
302+
// convert bool or int to string
303+
to_string :: proc{bool_to_string, int_to_string}
304+
```
305+
284306
## Array Programming (Operator Overloading)
285307

286308
## Arrays / Slices

0 commit comments

Comments
 (0)