Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!ukc!stl!stc!root44!gwc From: gwc@root.co.uk (Geoff Clare) Newsgroups: comp.lang.c Subject: Re: ANSI/Non-ANIS Function Declaration Macros Keywords: Unix, Wanted Message-ID: <1066@root44.co.uk> Date: 12 Dec 89 12:30:07 GMT References: <4603@itivax.iti.org> Reply-To: gwc@root.co.uk (Geoff Clare) Organization: UniSoft Ltd, London, England Lines: 45 In article <4603@itivax.iti.org> scs@itivax.iti.org (Steve Simmons) writes: > >Currently I'm writing code that must compile with and without ANSI >C features. Ideally this could be done with no slgging the code >with lots of #ifdef constructs like > >#ifdef __STDC__ >int *foo( int const a ) >#else >int *foo( a ) >int a ; >#endif >{ > func body >} > >While this works, it's got a weakness. In having two separate declarations, >one can over time let them get out of sync. It's also a pain to write. >Has anybody come up with a way of doing this so that I write the declarations >once and once only? Bizarre constructs considered within limits. My recommendation is that you do the following: #ifndef __STDC__ #define const #endif int *foo(a) const int a; Old style declarations are accepted equally well by ANSI compilers as 'common C' ones. The only thing that needs to be dependent on __STDC__ being defined is the 'const' keyword. "But what do I do about prototypes?" I hear you ask. My answer is the same: just stick to old-style 'extern' declarations. The advantage of using prototypes is that you don't need to worry about casting function arguments correctly all the time. But if your code must compile with non-ANSI compilers, you're going to have to cast all the arguments anyway - so the prototypes are redundant. -- Geoff Clare, UniSoft Limited, Saunderson House, Hayne Street, London EC1A 9HH gwc@root.co.uk (Dumb mailers: ...!uunet!root.co.uk!gwc) Tel: +44-1-315-6600