Deutsch English Français Italiano |
<86ed6lebp8.fsf@linuxsc.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch <tr.17687@z991.linuxsc.com> Newsgroups: comp.lang.c Subject: Re: size_t best practice Date: Sun, 18 Aug 2024 14:57:23 -0700 Organization: A noiseless patient Spider Lines: 21 Message-ID: <86ed6lebp8.fsf@linuxsc.com> References: <VdCcne2MOeshN1z7nZ2dnZfqnPWdnZ2d@brightview.co.uk> <operator-20240818131412@ram.dialup.fu-berlin.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Sun, 18 Aug 2024 23:57:23 +0200 (CEST) Injection-Info: dont-email.me; posting-host="c515e38b156ea485062cf8517e8b6236"; logging-data="2668448"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tscoQSX2mfpL2Jy2f25hGXmZ2ol7tHzA=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:jyiUwIMzVIx/xffbv7Q2cyl+hac= sha1:BKUs/fy0R5CFeoI4dWz7dI/ADa8= Bytes: 1860 ram@zedat.fu-berlin.de (Stefan Ram) writes: > 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; } Besides this facility not being a solution to the underlying problem, C++ has diverged from C to the point where it is no longer possible to program in C++ as "basically C".