Path: csiph.com!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: How About Disallowing Assignments In Expressions? Date: Fri, 09 Feb 2024 09:49:19 -0800 Organization: None to speak of Lines: 27 Message-ID: <87fry1edeo.fsf@nosuchdomain.example.com> References: <87r0hlef8q.fsf@nosuchdomain.example.com> <20240209093537.386@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: dont-email.me; posting-host="639f38d912c33920e0e5a36e0f09675f"; logging-data="2871694"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18nG6eYHjoLkGVa2HJSXAN3" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:RwNHHkGANItcaw+7ekzL5J3y6ZA= sha1:5wULZxxxIJoCKXAO1Eko2PKvG5U= Xref: csiph.com comp.lang.c:382213 Kaz Kylheku <433-929-6894@kylheku.com> writes: > On 2024-02-09, Keith Thompson wrote: >> I suggest that the bug of using "=" where "==" was intended occurs >> almost exclusively among inexperienced C programmers, particularly those >> who are inexperienced with programming in general. > > Almost exclusively. I've had this sneak upon me maybe once or twice in > the past 15 years. GCC warns well in most situations in which the typo > is made, so it doesn't easily sneak through. > > This is in the bug category of "used to be menacing before we had better > diagnostics", along with forgetting to include before using > malloc. One issue with C is that its syntax is what I think of as "dense". In more verbose languages (Ada is an example), a typo is very likely to result in an easily diagnosable syntax error. In C, many typos result in syntactically valid code that means something different. Examples are = vs ==, > vs >>, etc. Compilers can detect and warn about some things that are likely to be typos, like `if (a = b)`, but certain kinds of errors are still easier to make in C than in some other languages. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Medtronic void Void(void) { Void(); } /* The recursive call of the void */