* Re: [9fans] function inconsistently declared
@ 2002-10-01 16:44 rog
0 siblings, 0 replies; 6+ messages in thread
From: rog @ 2002-10-01 16:44 UTC (permalink / raw)
To: 9fans
[-- Attachment #1: Type: text/plain, Size: 68 bytes --]
don't mix ANSI and non-ANSI function declarations and definitions!
[-- Attachment #2: Type: message/rfc822, Size: 1610 bytes --]
From: "Zoltan Jarai" <jarai@mail.tvnet.hu>
To: 9fans@cse.psu.edu
Subject: [9fans] function inconsistently declared
Date: Tue, 1 Oct 2002 18:23:26 +0200
Message-ID: <9b9bee4f2f9cf8257bfa185a67d8f8d5@mail.tvnet.hu>
I suspect this must be elementary but could someone, please, enlighten
me why the code fragment below produces an error message:
cpu% 8c -FVw c.c
c.c:4 function inconsistently declared: f
cpu% cat c.c
int f(int,char);
int f(a,b)
int a;
char b;
{
return a+b;
}
cpu%
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9fans] function inconsistently declared
2002-10-01 17:42 C H Forsyth
@ 2002-10-02 9:01 ` Douglas A. Gwyn
0 siblings, 0 replies; 6+ messages in thread
From: Douglas A. Gwyn @ 2002-10-02 9:01 UTC (permalink / raw)
To: 9fans
C H Forsyth wrote:
> in old C,
> f(a, b)
> int a;
> char b;
> {
> ...
> }
> actual parameters for b were always promoted to int
> (since prototypes weren't available, and the compiler didn't maintain a
> file of the types of parameters to internal and external functions, it
> had to assume int for char, double for float etc.)
Actually it didn't *have* to, but it was convenient for the way
PDP-11 function linkage worked.
In the presence of a prototype, it is quite possible for the
compiler to use a linkage that differs from the one used for
unprototyped functions. In this regard also remember that
use of a variable-argument function requires that the ,...)
prototype be visible; quite a few systems use a linkage for
that situation that is different from the one for unprototyped
functions. I still occasionally have to fix up some legacy
code like:
error("foo %d\n",1); /* no prototype in scope */
error("punt\n");
...
void error(char *fmt, int x) {
... something involving &x
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9fans] function inconsistently declared
@ 2002-10-01 17:42 C H Forsyth
2002-10-02 9:01 ` Douglas A. Gwyn
0 siblings, 1 reply; 6+ messages in thread
From: C H Forsyth @ 2002-10-01 17:42 UTC (permalink / raw)
To: 9fans
[-- Attachment #1: Type: text/plain, Size: 302 bytes --]
in old C,
f(a, b)
int a;
char b;
{
...
}
actual parameters for b were always promoted to int
(since prototypes weren't available, and the compiler didn't maintain a
file of the types of parameters to internal and external functions, it
had to assume int for char, double for float etc.)
[-- Attachment #2: Type: message/rfc822, Size: 1553 bytes --]
From: "Zoltan Jarai" <jarai@mail.tvnet.hu>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] function inconsistently declared
Date: Tue, 1 Oct 2002 18:51:29 +0200
Message-ID: <3240710031bd9277e11a3841ab24d68c@mail.tvnet.hu>
Thanks for the quick replies! What was really baking my noodle was
that if all arguments are int's the function compiles. So I guess the
compiler just ignores pre-ANSI declaration and assumes int.
Thanks,
Zoli
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9fans] function inconsistently declared
@ 2002-10-01 16:51 Zoltan Jarai
0 siblings, 0 replies; 6+ messages in thread
From: Zoltan Jarai @ 2002-10-01 16:51 UTC (permalink / raw)
To: 9fans
Thanks for the quick replies! What was really baking my noodle was
that if all arguments are int's the function compiles. So I guess the
compiler just ignores pre-ANSI declaration and assumes int.
Thanks,
Zoli
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9fans] function inconsistently declared
@ 2002-10-01 16:32 Russ Cox
0 siblings, 0 replies; 6+ messages in thread
From: Russ Cox @ 2002-10-01 16:32 UTC (permalink / raw)
To: 9fans
the compiler treats mixing
ansi prototypes and pre-ansi function
declarations as an inconsistent declaration.
russ
^ permalink raw reply [flat|nested] 6+ messages in thread
* [9fans] function inconsistently declared
@ 2002-10-01 16:23 Zoltan Jarai
0 siblings, 0 replies; 6+ messages in thread
From: Zoltan Jarai @ 2002-10-01 16:23 UTC (permalink / raw)
To: 9fans
I suspect this must be elementary but could someone, please, enlighten
me why the code fragment below produces an error message:
cpu% 8c -FVw c.c
c.c:4 function inconsistently declared: f
cpu% cat c.c
int f(int,char);
int f(a,b)
int a;
char b;
{
return a+b;
}
cpu%
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2002-10-02 9:01 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-01 16:44 [9fans] function inconsistently declared rog
-- strict thread matches above, loose matches on Subject: below --
2002-10-01 17:42 C H Forsyth
2002-10-02 9:01 ` Douglas A. Gwyn
2002-10-01 16:51 Zoltan Jarai
2002-10-01 16:32 Russ Cox
2002-10-01 16:23 Zoltan Jarai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).