mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-04 12:07:45 +00:00
Basic when statement - Compile time if statement
This is similar to an #if in C but handled during the semantic checking stage.
This commit is contained in:
@@ -1,11 +1,27 @@
|
||||
#import "fmt.odin"
|
||||
// #import "fmt.odin"
|
||||
#import "utf8.odin"
|
||||
|
||||
when ODIN_OS == "window" {
|
||||
when ODIN_OS != "window" {
|
||||
} else {
|
||||
MAX :: 64
|
||||
}
|
||||
#import "fmt.odin"
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
|
||||
main :: proc() {
|
||||
MAX :: 64
|
||||
when true {
|
||||
OffsetType :: type int
|
||||
}
|
||||
|
||||
// MAX :: 64
|
||||
buf: [MAX]rune
|
||||
backing: [MAX]byte
|
||||
offset: int
|
||||
offset: OffsetType
|
||||
|
||||
|
||||
msg := "Hello"
|
||||
count := utf8.rune_count(msg)
|
||||
@@ -17,16 +33,17 @@ main :: proc() {
|
||||
s := msg[offset:]
|
||||
r, len := utf8.decode_rune(s)
|
||||
runes[count-i-1] = r
|
||||
offset += len
|
||||
offset += len as OffsetType
|
||||
}
|
||||
|
||||
offset = 0
|
||||
for i := 0; i < count; i++ {
|
||||
data, len := utf8.encode_rune(runes[i])
|
||||
copy(backing[offset:], data[:len])
|
||||
offset += len
|
||||
offset += len as OffsetType
|
||||
}
|
||||
|
||||
reverse := backing[:offset] as string
|
||||
fmt.println(reverse) // olleH
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user