Deutsch English Français Italiano |
<20240818154013.00002ed7@yahoo.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Michael S <already5chosen@yahoo.com> Newsgroups: comp.lang.c Subject: Re: size_t best practice Date: Sun, 18 Aug 2024 15:40:13 +0300 Organization: A noiseless patient Spider Lines: 22 Message-ID: <20240818154013.00002ed7@yahoo.com> References: <VdCcne2MOeshN1z7nZ2dnZfqnPWdnZ2d@brightview.co.uk> <operator-20240818131412@ram.dialup.fu-berlin.de> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Date: Sun, 18 Aug 2024 14:39:36 +0200 (CEST) Injection-Info: dont-email.me; posting-host="909e344cb8e3ca5d8a6a594a2d11c05b"; logging-data="2440532"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19dNKv5R8qSKVF2W8YboD4nH++FBfWHGJo=" Cancel-Lock: sha1:n4ngerokCCyJFqmt23gn97jK0Q8= X-Newsreader: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-w64-mingw32) Bytes: 1803 On 18 Aug 2024 12:17:36 GMT ram@zedat.fu-berlin.de (Stefan Ram) wrote: > Mark Summerfield <mark@qtrac.eu> wrote or quoted: > >So is it considered best practice to use int, long, long long, or > >size_t, in situations like these? > > In *cough*C++*cough* you could whip up a "SafeSize" class with > a bulletproof "operator--", so you don't space on the check. > You could still keep cranking out your code in what's basically C > and just cherry-pick this one gnarly feature from that other language. > > SafeSize& operator--() > { if( value == 0 ) > { throw std::underflow_error("SafeSize decrement underflow"); } > --value; > return *this; } But that's not a desired behavior for people that want to write downcounting for() loops in intuitive manner.