Skip to main content.
home | support | download

Back to List Archive

Re: Fails to compile as ANSI or K&R

From: Mark Gaulin <gaulin(at)not-real.globalspec.com>
Date: Wed Oct 07 1998 - 14:13:11 GMT
Hi Kenneth
I am on NT (and did the Win32 port of 1.2). I would have loved to completely
convert the code to ANSI but I did not consider that to be a "safe" thing
for me to do... after all, I'm using a MS compiler, and what's good for MS
is (usually) not good for someone else.

if your compiler does not want to mix ANSI and K&R function
definitions then you can turn off ANSI declarations by commenting out
the #define of "FUNCTION_PROTOTYPES_INCLUDE_ARGS" in the
file config.h.  If you look a little further down in config.h you will see the
definition of the macro _AP() which controls how the function prototypes
are seen by your compiler.  This ought to go a long way toward getting
it to compile.

It seems to me that by now all C compilers ought to be ANSI compatible.
Most compilers are forgiving enough to let you mix and match, which is
pragmatic but sad from the point of view of actually reaping the benefits
of the ANSI standard. A big question when doing the port was "What will 
gcc do on other platforms with respect to ANSI function definitions?"  
If there was a consensus that ANSI-style function definitions are ok then
I would replace all of the K&R functions with ANSI ones. (My C++ background
makes me hate the K&R style anyway.)

	Mark


At 05:08 PM 10/6/98 -0700, Kenneth Green wrote:
>Folks,
>
>   ** Please reply by direct email to kenneth_green@hp.com **
>
>I just downloaded the 1.2 release of Swish-E to make the upgrade from
>the 1.1 release.
>
>To my dismay I have found that the source code is neither strictly
>K&R nore strictly ANSI compatible. Some samples from the code of
>the K&R and ANSI violations are given below.
>
>While I understand that gcc has a 'forgiving' (some would say slack;-)
>mode, the HP compilers do not, and in require strict adherence to
>the standards.
>
>I cannot understand how these basic violations could be present unless
>I am the only one in the world not using gcc !
>
>In any case I would be interested in hearing from anyone who has
>struck these problems and has a solution, other than editting all
>of the violating source code to make it genuinely ANSI compatible.
>
>Sample K&R violations:
>
> File:    http.c
> Code:    void indexpath(char *url)
> Problem: This is an ANSI "new style" function definition which is
>          not parsable by a strict K&R compiler
>
> File:    index.c
> Code:     .... 10.0f)
> Problem: The 'f' suffix indicating 'float' is an ANSI feature. For
>          K&R code you must use a prefix type cast like: "(float)10.0"
>
>Sample ANSI violations:
>
> File:    check.h, check.c
> Code:    declaration = int isvowel _AP ((char));
>          definition  = int isvowel(c)
>                            char c; 
> Problem: ANSI requires the declaration and definition styles to
>          match. Here we have a 'new style' declaration with an
>          'old style' definition.
>
>          One reason this is a problem relates to the type expansion
>          and contraction performed by the compiler on the formal
>          parameters.
>
>
>Regards,
>Kenneth
>-- 
>========================================================================
>Kenneth Green                           +61 3 9210 5541 Tel. & Voicemail
>R&D Project Manager                     +61 3 9210 5550 FAX
>                                        kenneth_green@hp.com
>Advanced Networks Division              PO Box 221, Blackburn Vic 3130
>Hewlett-Packard Australia Ltd           AUSTRALIA
>========================================================================
> 
Received on Wed Oct 7 07:25:35 1998