Summary of Responses on Spaces after Function Names
Phillip L. Shaffer
pls at ncsu.UUCP
Fri Dec 7 01:07:28 AEST 1984
Some weeks ago, I posted a query about a C compiler that complained
about spaces after undeclared function names. I received 10 responses,
8 of which said the compiler was broken, and 2 that suggested the
compiler was correct. I consider the argument to be settled
the compiler is wrong. I have repeated the two most forceful arguments
below for this point of view, one of which is from the chairman of
the relevant ANSI language subcommittee. I have also repeated
the two arguments against this opinion, in the interest of fairness.
I thank all those who responded. I'll let you know what Eco-Soft has
to say.
For the record, I first repeat my query, for those who didn't see it
or don't recall it.
Phil Shaffer (pls at ncsu)
--- the query: -----------------------------------------------------
I would like to obtain a consensus, or at least a few opinions, on
a minor point in C syntax. I have recently obtained the Eco-C
C compiler for my Z-80 machine, and and am generally happy. It
is doing one thing that I haven't seen before in other C compilers
(namely UNIX 4.2BSD or DeSmet on an IBM PC): it complains about
spaces after function names for funtions that have not been previously
declared - the error message is "illegal function call," or somesuch.
If you declare int functions before use, there is no problem.
Thus:
int foo();
foo ();
causes no problem, but
foo ();
generates the complaint. K&R (p. 186, paragraph 4) seem to sanction
this:
"a hitherto unseen identifier followed immediately by a left
parenthesis is contextually declared to represent a function
returning an integer; thus, in the most common case, integer-
valued functions need not be declared."
The question is: does "followed immediately" mean "with nothing
but white space in between" or is it to be taken literally?
This is a minor annoyance to me - changing styles slightly and
editing old programs before recompiling - but I thought I would
get some other opinions before complaining to Eco-Soft.
--- the arguments for "it's broken": --------------------------------
From: mcnc!decvax!genrad!mit-eddie!allegra!sfbc!lr
Date: Fri, 9 Nov 84 03:16:05 est
This is an easy one. "followed immediately" means with no tokens
in-between, and the compiler is clearly wrong. The only time space
before a parenthesis is significant is in a macro definition, to
distinguish a macro with no arguments:
#define foo (x)
which expands into (x) always, from
#define bar(x)
which requires an argument but expands into nothing always.
By the way, in invoking bar, either "bar(1)" or "bar (1)" are
acceptable.
The ANSI draft standard says
"A function call is a primary expression followed by parentheses ()
containing ..."
leaving out the misleading "immediately" and not melding in the
irrelevant presence of a prior declaration. (That is discussed
in the next paragraph.)
So go get the vendor to fix it!
Larry Rosler
Chairman, Language Subcommittee
ANSI X3J11 Committee
----------------------------------------------------------------------
Date: Thu, 22 Nov 84 12:11:06 mst
From: unmvax!unm-la!jay (Jay Plett)
In Section 2 of K&R's "C Reference Manual" (Lexical Conventions):
"Blanks ... are ignored except as they serve to separate
tokens. Some white space is required to separate other-
wise adjacent identifiers, keywords, and constants."
Nowhere does the Reference Manual suggest that white space delimits
anything else.
I take that to mean that white space is required to resolve ambiguities
such as:
int a, b;
a+++b;
but never to *alter* unambiguous contsructions such as:
foo /* a function */ (blah, blahbar);
----------------------------------------------------------------------
--- the arguments for "the compiler is correct: ----------------------
----------------------------------------------------------------------
Since spaces are significant in C (as opposed to FORTRAN), I suspect
Kernighan & Ritchie meant to be taken literally. I prefer the "foo()"
syntax anyway.
----------------------------------------------------------------------
My understanding was that since spaces are separators in C, the case of
foo ();
is invalid. I was taught that all functions need to be followed
*immediately* (as stated in K&R) by the parenthesis. when you say:
int foo ();
you are declaring something thoroughly incomprehensible to a K&R C
compiler.
----------------------------------------------------------------------
Thanks for the responses.
Phil Shaffer
More information about the Comp.lang.c
mailing list