Path: csiph.com!news.mixmin.net!aioe.org!.POSTED!not-for-mail From: "Rod Pemberton" Newsgroups: alt.os.development Subject: Re: Smaller C Date: Sun, 13 Sep 2015 03:47:01 -0400 Organization: Aioe.org NNTP Server Lines: 57 Message-ID: References: <1debc959-af42-490a-ac12-568e59fa441a@googlegroups.com> <458c2c3b-6b99-49db-b108-26d240369a74@googlegroups.com> <18829175-8bc7-4b9f-9516-392659ed15a5@googlegroups.com> <082e402b-40f7-46ed-a472-a940d2902030@googlegroups.com> <3318542b-e303-4454-bfb0-d4554304de6b@googlegroups.com> <0f114260-625f-4a96-b7df-6a1972525280@googlegroups.com> <94dbee89-6191-4cec-a491-d5ac974a3ffe@googlegroups.com> <77032cbf-7538-42ef-a1ad-73f3ca6ee38d@googlegroups.com> <13fd448e-f885-4785-9368-04c0b75e543c@googlegroups.com> <863a5219-999a-4028-b567-a8e1e282af5d@googlegroups.com> <79c0cfce-38ec-4bcc-bd5f-a25808ffb8ea@googlegroups.com> <39da71f8-7e21-4fcb-84da-263d5c81059f@googlegroups.com> NNTP-Posting-Host: n4wpt9zq8xR26Ttf9mo2BA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/12.16 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com alt.os.development:8767 On Sat, 12 Sep 2015 14:18:50 -0400, Benjamin David Lunt wrote: > For example, the following technique is seldom used but makes > for an excellent syntax check on the coder's point of view. > > if (2 == i) > > which, by the way, your compiler compiles just fine. > > The above technique, for those who have not seen it, makes > sure that the coder doesn't accidentally forget the second > '=' sign as in > > if (i = 2) // <-- coder should have done 'if (i == 2)' > > The above will produce a TRUE response every time no matter > what 'i' contains. The compiler won't catch it as a syntax > mistake since it is valid syntax. It would be up to the > coder to catch it. However, if the immediate is first, > the compiler will catch it every time. I've seen it, but not in any code after the early 1990's ... I recall older C coding guidelines having examples like that. AFAIR, the only recommendation I ever chose to use was to #define a mask and use with bitwise operators instead of using C's bitfields. Supposedly, bitfields weren't implemented properly in some of the older C compilers. You might also look for MISRA and Safer C which have a bunch of rules for safer C coding. "Indian Hill C Style and Coding Standards", an updated version http://ieng9.ucsd.edu/~cs30x/indhill-cstyle.html Ten C Commandments http://www.quut.com/c/ten-commandments.html Portable C http://web.archive.org/web/20110725164734/http://www.chris-lott.org/resources/cstyle/portableC.html Some C9X webpages on C99 changes via Wayback archive: http://web.archive.org/web/20070119191725/http://wwwold.dkuug.dk/JTC1/SC22/WG14/www/newinc9x.htm http://web.archive.org/web/20070807074051/http://home.tiscalinet.ch/t_wolf/tw/c/c9x_changes.html MISRA coding rules etc http://www.knosof.co.uk/misracom.html http://www.leshatton.org/index_SA.html Safer C http://www.saferc.com/ http://www.saferc.com/safer-c-toolset/ Rod Pemberton -- Just how many texting and calendar apps does humanity need?