Deutsch English Français Italiano |
<operator-20240818131412@ram.dialup.fu-berlin.de> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!fu-berlin.de!uni-berlin.de!not-for-mail From: ram@zedat.fu-berlin.de (Stefan Ram) Newsgroups: comp.lang.c Subject: Re: size_t best practice Date: 18 Aug 2024 12:17:36 GMT Organization: Stefan Ram Lines: 14 Expires: 1 Jul 2025 11:59:58 GMT Message-ID: <operator-20240818131412@ram.dialup.fu-berlin.de> References: <VdCcne2MOeshN1z7nZ2dnZfqnPWdnZ2d@brightview.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de jC2GpQlWEHVq0wSxuDpPQgJeDeqZNomLMVsLIM2wo15IvY Cancel-Lock: sha1:dm7wtuMdy5QqGkf7rVRnEX4GS0U= sha256:lgW1YebaQ5Ulqg2X58EzKOwY2nq5XkAQSxPdN7XfsBM= X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved. Distribution through any means other than regular usenet channels is forbidden. It is forbidden to publish this article in the Web, to change URIs of this article into links, and to transfer the body without this notice, but quotations of parts in other Usenet posts are allowed. X-No-Archive: Yes Archive: no X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some services to mirror the article in the web. But the article may be kept on a Usenet archive server with only NNTP access. X-No-Html: yes Content-Language: en-US Bytes: 1915 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; }