Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connectionsPath: ...!weretis.net!feeder9.news.weretis.net!2.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: size_t best practice Date: Sun, 18 Aug 2024 15:23:58 -0700 Organization: A noiseless patient Spider Lines: 46 Message-ID: <86a5h9eagx.fsf@linuxsc.com> References: <20240818154013.00002ed7@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Mon, 19 Aug 2024 00:23:59 +0200 (CEST) Injection-Info: dont-email.me; posting-host="8e0243d997a628e731b4ff9e397b6328"; logging-data="2668448"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UOEpMi9Xs46EemnhraEfwFgmfsCpbv1U=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:LPlWuxNTf+kqbLTxmpNdPsTCgJ4= sha1:CwOcy1AtRKyj7NlHcuoJN/JkURc= Bytes: 3127 Michael S writes: > On 18 Aug 2024 12:17:36 GMT > ram@zedat.fu-berlin.de (Stefan Ram) wrote: > >> Mark Summerfield 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. Kind of a funny use of the word intuitive, for two reasons. The first is that writing for() loops, especially C for() loops, is learned behavior. There can be patterns that one is used to, but they are not "intuitive" in the usual sense of the word. The second is that people who program in C are accustomed to the idea of an asymmetry between counting up and counting down, because of how pointers work. It's okay to increment a pointer to one past the end of an array; it is not okay to decrement a pointer to one before the beginning of an array. Because of that the patterns for going forward and for going backward are just different. It seems odd to use the word "intuitive" to recognize that distinction. Which is not to say I disagree with what you are saying. Actually I guess I'd have to say I'm not sure what it is you are saying. To my way of thinking the function above doesn't change the way I would write down-counting loops. It might be useful as a debugging aid aide, but nothing more (and an assert() is probably better). I think though that what you're saying is something else but I'm not sure what it is.