odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.55k stars 570 forks source link

Runtime assertion when appending to dynamic arrays of empty structs #267

Closed Breush closed 5 years ago

Breush commented 5 years ago
package main

Token :: struct {
    // Empty
};

main :: proc() {
    tokens : [dynamic]Token;

    token : Token;
    append(&tokens, token);
}

The above code fails on Linux (other platforms are not tested) with:

/home/breusta/dev/odin/core/os/os_linux.odin(222:2) Runtime assertion
Tetralux commented 5 years ago

Does not occur on Windows 10 x64. (Commit 1a4e25f14149428ff19f2da239abe54ff0083632).

On Tue, 2 Oct 2018 at 08:56 A. Breust notifications@github.com wrote:

package main

Token :: struct { // Empty };

main :: proc() { tokens : [dynamic]Token;

token : Token;
append(&tokens, token);

}

The above code fails on Linux (other platforms are not tested) with:

/home/breusta/dev/odin/core/os/os_linux.odin(222:2) Runtime assertion

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/odin-lang/Odin/issues/267, or mute the thread https://github.com/notifications/unsubscribe-auth/ABST0KHU8aZBBDZH-vQPl9guEGqMHB-Oks5ugyo4gaJpZM4XDmd3 .

gingerBill commented 5 years ago

Currently in Odin, size_of(struct{}) is 0 whilst in C/C++ it is 1. I am not so sure what the best approach is for this. And I have a hunch that this may be partially the reason for the bug.