Typing `: [1024]u8 = undefined` Less?

Your point makes sense.

Another reason I do not expect inline functions to be able to return a stack pointer is that symbols defined within an inline function should exist in a different scope.

Considering that the following code is also illegal, it is even less reasonable for inline functions to be allowed to return stack pointers.

const p = blk: {
    const a: u8 = getA();
    break :blk &a;
}

A question: I would really appreciate it if Zig’s inline semantics meant that it is guaranteed to inline. But conversely, will it still perform inlining optimizations without inline? Based on experience with other languages, I often deliberately avoid writing inline to prevent interfering with the compiler’s optimizations. If Zig’s philosophy is to require explicit inline, I might need to correct this and try to use inline more frequently!

4 Likes

Don’t quote me on that but even functions that are not marked inline will be inline if that makes sense from an optimization stand point, but inline keyword will indeed inline the function.

Language Reference - Functions

// The inline calling convention forces a function to be inlined at all call sites.
// If the function cannot be inlined, it is a compile-time error.
inline fn shiftLeftOne(a: u32) u32 {
    return a << 1;
}

To be extra clear don’t litter your code with inline, as it’s usually not the best thing to do, and it’s usually better to rely on the optimizer heuristics, but when you know that something needs to be inlined, you can actually force it, not just “hint” it, which is great because you have the final word, not the inline heuristic

5 Likes

It’s not the feature in of itself that is the problem, rather it’s “I want macros!” which leads to misinterpreting semantically inlined as “text replace!!”. You see may what you look for, even if It’s not there.

3 Likes