From f08bc460b79260d7b5e7653faf3d30cb079cfed7 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Tue, 7 Jan 2025 11:46:43 +0800 Subject: malloc: Return _, ESTACK instead of 0, ESTACK --- language_description.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/language_description.md b/language_description.md index 63041d5..1e24066 100644 --- a/language_description.md +++ b/language_description.md @@ -41,15 +41,14 @@ func malloc(size_t s) (void*, error) { /* What malloc is supposed to do */ return ptr, NIL; } onfail { - return 0, ESTACK; + return _, ESTACK; } ``` If something causes `malloc` to be uncallable, e.g. if there is insufficient stack space to hold its local variables, it simply returns a meaningless -pointer and a non-nil error value. Note that although we return "`0`" in the -example code above, the zero pointer is not guaranteed to be an invalid pointer -in e². +pointer and a non-nil error value. Returning the empty identifier `_` means +that the return value is undefined and may be uninitialized. Other functions may have different methods of failure. Some might return an error, so it might be natural to set their error return value to something like -- cgit v1.2.3