Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!sdcsvax!ucbvax!hoptoad!gnu From: gnu@hoptoad.uucp (John Gilmore) Newsgroups: comp.lang.c Subject: Kinds of code broken by ANSI C Message-ID: <3724@hoptoad.uucp> Date: 23 Dec 87 02:23:38 GMT References: <4668@pyr.gatech.EDU> <2046@haddock.ISC.COM> Organization: Nebula Consultants in San Francisco Lines: 47 karl@haddock.ISC.COM (Karl Heuer) wrote: > Can you really find a lot of examples of code that will be broken (not just > deprecated) by the new standard? No fair using code that was already > nonportable under K&R but just happened to work on your compiler. > > The only one that springs to my mind is mktemp("fooXXXXXX") (because it's no > longer safe to assume that string literals are writable). I have been porting 4.3BSD through gcc and finding a bunch of things. Many are nonportabilities -- preprocessor abuse and referencing members of other structures are the most common -- but some are not. One that comes to mind is functions that do: foo() { extern int errno; errno = 0; ... } bar() { if (errno) ... } ANSI C defines the "extern int errno;" to be local to foo(), so bar() must redeclare errno before it can use it. K&R defined it to be global. Another is that various programs used the identifier "signed". Another is programs that had unbalanced quotes inside #if 0. Another is programs that do: typedef int flag; foo(flag) int flag; {...} which has gotten hard to parse in ANSI C and is now disallowed. I can show you Unix source code that uses all these features. I will probably end up writing a paper for Usenix about it... -- {pyramid,ptsfa,amdahl,sun,ihnp4}!hoptoad!gnu gnu@toad.com I forsee a day when there are two kinds of C compilers: standard ones and useful ones ... just like Pascal and Fortran. Are we making progress yet? -- ASC:GUTHERY%slb-test.csnet