~sircmpwn/hare-users

1

Noob question about stack allocated string

Details
Message ID
<080a86c93f4002570edcfa1ffd27f17a.bruma@mailbox.org>
DKIM signature
pass
Download raw message
hello, say I have a function that returns a string created with 
fmt::bsprintf:

	fn stackstr() str = {
		let b: [128]u8 = [0...];
		return fmt::bsprintf(&b, "{} {}!", "hello", "world");
	};

the question is: Is this fundamentally incorrect because functions
shouldn't return stack allocated strings? As I understand it string are 
like pointers so the caller does not copy the string.

Thank you
Details
Message ID
<CSZFGA5KPGEI.Z9JUF9CMMPDI@monch>
In-Reply-To
<080a86c93f4002570edcfa1ffd27f17a.bruma@mailbox.org> (view parent)
DKIM signature
pass
Download raw message
On Tue May 30, 2023 at 7:16 AM UTC, bruma wrote:
> the question is: Is this fundamentally incorrect because functions
> shouldn't return stack allocated strings? As I understand it string are 
> like pointers so the caller does not copy the string.

yes, that's correct
Reply to thread Export thread (mbox)