Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!samsung!think!ames!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: main() linkage Message-ID: <11697@smoke.BRL.MIL> Date: 28 Nov 89 18:24:59 GMT References: <2387@stl.stc.co.uk> <744@lakart.UUCP> <0175@sheol.UUCP> <11621@smoke.BRL.MIL> <7744@cdis-1.uucp> <11665@smoke.BRL.MIL> <1122@cirrusl.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 54 In article <1122@cirrusl.UUCP> dhesi%cirrusl@oliveb.ATC.olivetti.com (Rahul Dhesi) writes: >What is erroneous programming practice? >One overly simple definition is "programming practice that violates the >ANSI C standard". Which is not a very useful definition when >considering code that was written before the ANSI C standard came into >being. That's probably why nobody would propose such a "definition". However, note that code that unnecessarily depends on details of a C implementation is inherently less portable than it could have been. >I have seen the usual use of printf to be considered an error waiting >to be fixed. (I have even seen Ritchie as being quoted as saying >something like this.) But if K&R defined the C programming language in >a certain way, and that definition required printf to be used in a >certain way, and if millions of lines of existing *correctly working >code* uses printf, thow can that usage possibly be erroneous? It's not erroneous, just dependent on a certain practical implementation constraint (namely, that the abuse of function linkage exemplified by printf() be somehow made to work) that X3J11 decided to remove. The C language never officially supported functions like printf(), although a reasonable C implementor would generally take it into account when designing his function linkage technique, because the customers expected it to work. A generally better solution is now officially part of Standard C. >On the other hand, existing code can stop working through no fault of >its own, if compilers are changed to no longer compile it correctly. That's between you and your compiler vendor. It has always been the case that depending on implementation quirks could mean that your code could stop working with a new release of the compiler. >So was it portable to declare main() to return void? As always, >portability depends on your universe. Within the universe of C >implementations that supported the language as defined by K&R, which >was roughly equivalent to the universe of existing C implementations, >it was always portable to declare main() to return anything you wanted, >provided you always existed by calling exit. *That has not changed*. Wrong, wrong, wrong. Misdeclaring function return types has ALWAYS been a violation of the C language specification, well before X3J11. You happen to have been able to get away with it on the limited range of implementations you have had access to. That does not mean that your violations of the language spec have been "portable", merely that you hadn't yet been bit by them. >What has changed is universe of existing C implementations, and it has >changed because the meaning of "C" has changed. That's not the problem..