Article View: comp.std.c
Article #4367Re: macro versus function in standard headers
From: Norman Diamond
Date: Fri, 17 Nov 1995 03:19
Date: Fri, 17 Nov 1995 03:19
52 lines
3054 bytes
3054 bytes
>>> Is a conforming implementation _required_ to give a diagnostic if presented
>>> with the following source:
>>> #include <stdlib.h>
>>> int main(void) { return abs("0"); }
>>> ...
>>> or does one need to write (abs)("0") ... to be assured of the diagnostic.
>> I do not see any Constraint or Syntax rule requiring a diagnostic for
>> this violation [in either case].
>6.3.2.2/3.3.2.2 Function calls
# Constraints
# ...
# If the expression that denotes the called function has a type that
# includes a prototype, the number of arguments shall agree with the
# number of parameters. Each argument shall have a type such that its
# value may be assigned to an object with the unqualified version of
# the type of its corresponding parameter.
Yes Mark, the implementation can choose to impose on itself the requirement
to issue diagnostics, by choosing to declare abs with a prototype when
the program has #include <stdlib.h>. The implementation can also choose
to impose on itself a requirement to issue diagnostics for any other reason,
such as advertising a claim to provide quality control assistance. However,
the implementation can choose not to do so. The implementation's <stdlib.h>
has to declare abs but does not have to declare a prototype for it.
>7.10.6.1/4.10.6.1 shows the prototype for abs() and
>it has an argument type of int.
7.10.6.1/4.10.6.1 has the line
#include <stdlib.h>
right above the line
int abs(int j);
Does this mean that <stdlib.h> is required to #include itself before
declaring abs with a prototype? No Mark, the section is labelled
"Synopsis." It describes what programs have to do or what alternative
methods used by programs must be equivalent to. Implementations can
contain libraries and standard headers that are not even coded in C and
do not have a prototype anywhere in sight, as long as the implementations
work for valid programs and as long as they yield diagnostics for programs
that violate the syntax and constraints on programs.
>However, it is desirable for implementations to be so restricted, [...]
>I would favor a corrigendum making it clear that the constraint does apply.
As mentioned before, I also wouldn't mind seeing such a corrigendum.
--
<< If this were the company's opinion, I would not be allowed to post it. >>
"I paid money for this car, I pay taxes for vehicle registration and a driver's
license, so I can drive in any lane I want, and no innocent victim gets to call
the cops just 'cause the lane's not goin' the same direction as me" - J Spammer
Technical Details
Message-ID:
<48guvu$h68@usenet.pa.dec.com>Path:
arc1-ca.pugleaf.net!jrd.dec.com!diamondReferences:
<487rls$rci@newshost.lanl.gov> <48caqa$rl@usenet.pa.dec.com> <1995Nov15.103729.9184@sq.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!jrd.dec.com!diamond From: diamond@jrd.dec.com (Norman Diamond) Newsgroups: comp.std.c Subject: Re: macro versus function in standard headers Date: 17 Nov 1995 03:19:26 GMT Organization: DEC Japan Research and Development Center Distribution: world Message-ID: <48guvu$h68@usenet.pa.dec.com> References: <487rls$rci@newshost.lanl.gov> <48caqa$rl@usenet.pa.dec.com> <1995Nov15.103729.9184@sq.com> NNTP-Posting-Host: jit533.jrd.dec.com