Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.std.c Subject: Re: Addition of nocode keyword Date: Sat, 26 Oct 2019 22:52:05 +0100 Organization: A noiseless patient Spider Lines: 102 Message-ID: <87k18rtbsq.fsf@bsb.me.uk> References: <942b0023-9e69-4fb1-b382-e720d87e0d62@googlegroups.com> <878sp8v44k.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="765087fe9670a5b89e1c7e0ebc313c46"; logging-data="14954"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/NNYCn+Xh9mjRHDs6u8d76Mep4t+HsTco=" Cancel-Lock: sha1:QzE6BG7ZQFr9IKIk/GSupPDzncs= sha1:qxbw5CyHCSc+MmPvBx9pF3YGtXE= X-BSB-Auth: 1.b10760aeaba6813aae06.20191026225205BST.87k18rtbsq.fsf@bsb.me.uk Xref: csiph.com comp.std.c:6001 "Rick C. Hodgin" writes: > On 10/25/2019 6:42 PM, Ben Bacarisse wrote: >> C already ... has an empty statement. All of these are human- >> language agnostic ways to do the same thing as "nocode". > > I'm not aware of them. Can you teach me? I am sure you know them; I must have simply not have been clear. The expression in an expression statement is optional, as are the contents of a compound statement, so ; {} {;} {;;} and so on (with optional comments) are all increasing insistent ways of saying that no code was really, really what was intended. > In C today, how would you deterministically identify or signify > that this block of code's logic test was intentionally left empty? > > for (x = 0; ; ++x) > { > // Code here > } I don't understand the question. The best way to show intent to a reader (when it really is in doubt) is with a comment, and the best was to show intent to a compiler is by writing code with the intended meaning. Maybe I don't know what "deterministically identify" means. If you are talking about giving permission for a compiler to issue a warning for the above then it already has it. It could, perfectly legally, say something like "Did you intend to leave the condition empty? To silence this warning, write an explicitly always true expression.". > Or this one: > > for (i = 0; ; ) > { > } > > How do you know the empty portions weren't left out by mistake? The surest way for me to know is to understand the code. Have you come across an example where such a thing is an accident and yet it's not obviously wrong? I feel (without evidence) that any code like that will be bad code for all sorts of other, more significant, reasons so I'd like to see an example. > Without nocode or something like it, there's no way for the com- > piler to know. See above. The compiler can be suspicious about anything it likes and can warn the programmer along with offering advice about what will make it (the compiler) shut up. You could even document a special meaning for an option: -Waccidentally-empty that turns on these warnings while at the same time behaving like -Dnocode. You could then write for (i = 0; nocode; nocode) nocode; a get no warnings even when compiled with -Waccidentally-empty. > There's no way for another developer to know > either without something like this: > > for (x = 0; /*no test here*/; ++x) > { > // Code here > } I would hope there is! Do you have an actual example where it is not obvious that the empty test was intended? If you do, at the very least, the code needs a comment which probably should explain more than your example comment does. > But what if in this online world we get some code from some > foreign language? Rely on Google Translate to convey what it > means? > > for (x = 0; /*لا يوجد اختبار هنا*/; ++x) > { > // Code here > } > > There's no way to know with certainty, and that's the issue. Unless you are proposing a breaking change by /insisting/ on something compiler-checkable, then I don't see how your suggestion helps for code written by anyone else. Other people will always be able to write the form you obect to, and they can currently write explicit always-true expressions and explicitly empty code (of any degree of complexity) if they feel the intent is not clear. And if they don't think they need to make themselves extra clear, they probably won't use any new keywords either. -- Ben.