Deutsch   English   Français   Italiano  
<9B-cnS6A5ZSt7jD7nZ2dnZfqn_udnZ2d@giganews.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Paul Rubin <no.email@nospam.invalid>
Newsgroups: comp.lang.forth
Subject: Re: Numeric string output - conspicuously absent in Forth
Date: Wed, 01 May 2024 21:41:53 -0700
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <8734r025bi.fsf@nightsong.com>
References: <662f2cd2$1@news.ausics.net> <87sez4m941.fsf@nightsong.com>
	<v0otfs$1t6r0$1@dont-email.me> <871q6nj3el.fsf@nightsong.com>
	<v0rfle$2kkku$2@dont-email.me> <66319f99$1@news.ausics.net>
	<v0t45b$33a3j$1@dont-email.me> <66322fc8$1@news.ausics.net>
	<87bk5p13me.fsf@nightsong.com> <6632ff7e$1@news.ausics.net>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Thu, 02 May 2024 06:41:54 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="53d692dcf89c43b2bac7b58ead83de75";
	logging-data="3852582"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1940KmiKDvWkc2jIAv/jNnm"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:0hw/7M81+/BfZz0vQi2uA+TrcUw=
	sha1:pXUEIK6vGRe+ZvvLGlXUuPTTq6I=
Bytes: 2196

dxf <dxforth@gmail.com> writes:
> Perhaps implementations vary.  Subsequent to my question I remembered
> I had the source for a 'small-C' for CP/M.  Looking at the primitive for
> sprintf I found it uses a small static buffer.  The numeric string is
> built there after which it's copied to the user-designated buffer.

sprintf(buf, "%d", n) still works.  It's like snprintf except the buffer
size is not specified.  The buffer is instead assumed to be large enough
to hold the output.  That can obviously be dangerous, especially
considering %s for formatting strings, so snprintf is preferred.

Using a static buffer creates obvious thread safety issues if two calls
to sprintf are active at the same time.  The Linux man page for sprintf
and friends has the thread safety attribute "MT-Safe locale" for those
functions.  I don't know what that means exactly though.  In CP/M this
probably wasn't an issue.