| ... | @@ -3169,7 +3169,6 @@ const assert = @import("std").debug.assert; | ... | @@ -3169,7 +3169,6 @@ const assert = @import("std").debug.assert; |
| 3169 | // Functions are declared like this | 3169 | // Functions are declared like this |
| 3170 | fn add(a: i8, b: i8) i8 { | 3170 | fn add(a: i8, b: i8) i8 { |
| 3171 | if (a == 0) { | 3171 | if (a == 0) { |
| 3172 | // You can still return manually if needed. | | |
| 3173 | return b; | 3172 | return b; |
| 3174 | } | 3173 | } |
| 3175 | | 3174 | |
| ... | @@ -3193,12 +3192,18 @@ fn abort() noreturn { | ... | @@ -3193,12 +3192,18 @@ fn abort() noreturn { |
| 3193 | while (true) {} | 3192 | while (true) {} |
| 3194 | } | 3193 | } |
| 3195 | | 3194 | |
| 3196 | // nakedcc makes a function not have any function prologue or epilogue. | 3195 | // The nakedcc specifier makes a function not have any function prologue or epilogue. |
| 3197 | // This can be useful when integrating with assembly. | 3196 | // This can be useful when integrating with assembly. |
| 3198 | nakedcc fn _start() noreturn { | 3197 | nakedcc fn _start() noreturn { |
| 3199 | abort(); | 3198 | abort(); |
| 3200 | } | 3199 | } |
| 3201 | | 3200 | |
| | 3201 | // The inline specifier forces a function to be inlined at all call sites. |
| | 3202 | // If the function cannot be inlined, it is a compile-time error. |
| | 3203 | inline fn shiftLeftOne(a: u32) u32 { |
| | 3204 | return a << 1; |
| | 3205 | } |
| | 3206 | |
| 3202 | // The pub specifier allows the function to be visible when importing. | 3207 | // The pub specifier allows the function to be visible when importing. |
| 3203 | // Another file can use @import and call sub2 | 3208 | // Another file can use @import and call sub2 |
| 3204 | pub fn sub2(a: i8, b: i8) i8 { return a - b; } | 3209 | pub fn sub2(a: i8, b: i8) i8 { return a - b; } |