Newsgroups: comp.lang.c Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!barmar From: barmar@think.com (Barry Margolin) Subject: Re: moving towards the standard ANSI with old c code Message-ID: <1991Apr19.220613.24789@Think.COM> Sender: news@Think.COM Organization: Thinking Machines Corporation, Cambridge MA, USA References: <8452@umd5.umd.edu> Distribution: na Date: Fri, 19 Apr 91 22:06:13 GMT In article <8452@umd5.umd.edu> jjk@astro.umd.edu (Jim Klavetter) writes: >1. What is the timescale for all compilers to be ANSI? And what is >the timescale for most compilers not accepting old c (I know it is >often called K&R c, but I will use the term old C to mean nonANSI c)? Conformance with standards is purely voluntary in the US, driven by market forces. Government contracts generally require products that conform to national standards, so vendors who want to do business with the government will probably have conforming compilers as soon as possible. If compiler purchasers stop giving business to vendors who supply nonstandard compilers, they will become extinct pretty soon. The biggest problem is system vendors who include a C compiler with the OS -- purchasers of such systems generally don't base their decision just on the C compiler that is included, so they will often take a system with an old C compiler because they want the features of the rest of the system. >2. When should I be worrying about updating my libraries (if not my >programs) to ANSI c? Should this be done all at once or can I do it >as needed? Your best bet is to start as soon as possible, but update it into code that will work in both ANSI and pre-ANSI C. You can use macros to minimize the number of places where you must distinguish between the two dialects. For instance, you can put the following in a header file that all your code includes: #if _STDC_ == 1 #define ARGS(x) x #else #define ARGS(x) #endif Then you can write the following: int foo (ARGS((char*, int))); In ANSI C this will become a function prototype, and in pre-ANSI C it will become a function declaration. You can also try to find places in your code that are dependent on language features that are different in the two dialects, such as the automatic promotion of various arithmetic types during function calls, and recode them so that they work in both environments. Using techniques such as these, there's very little code that can't be made to run in both dialects. ANSI C was designed to be mostly upward compatible with most common pre-ANSI implementations of C. -- Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar