468,241 Members | 1,504 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,241 developers. It's quick & easy.

pre-ansi declarations

Which sections in the standard mandate that 'foo' below does
not qualify as a function that includes a prototype:

void foo(a)
char *a;
{
do_something(a);
}

int main(void)
{
foo();
return 0;
}

also, under 6.11.2 of c99, how is it possible
to declare a file scope object with internal linkage
without using 'static'?

--
j0mbolar

Feb 8 '06 #1
10 1250
"j0mbolar" <j0******@engineer.com> writes:
Which sections in the standard mandate that 'foo' below does
not qualify as a function that includes a prototype:

void foo(a)
char *a;
{
do_something(a);
}

int main(void)
{
foo();
return 0;
}
Probably the definition of "function prototype" in 6.2.1p2:

A _function prototype_ is a declaration of a function that
declares the types of its parameters.

The *definition* of foo() declares the type of a; the *declaration*
doesn't.
also, under 6.11.2 of c99, how is it possible
to declare a file scope object with internal linkage
without using 'static'?


I don't know. Anybody else?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 8 '06 #2

Keith Thompson wrote:
"j0mbolar" <j0******@engineer.com> writes:
Which sections in the standard mandate that 'foo' below does
not qualify as a function that includes a prototype:

void foo(a)
char *a;
{
do_something(a);
}

int main(void)
{
foo();
return 0;
}


Probably the definition of "function prototype" in 6.2.1p2:

A _function prototype_ is a declaration of a function that
declares the types of its parameters.

The *definition* of foo() declares the type of a; the *declaration*
doesn't.


So where default argument promotions do not apply,
do pre-ansi compilers infer the type in the above example
from 'a', so that they know it is a 'pointer to char'?

--
j0mbolar

Feb 8 '06 #3
"j0mbolar" <j0******@engineer.com> writes:
Keith Thompson wrote:
"j0mbolar" <j0******@engineer.com> writes:
> Which sections in the standard mandate that 'foo' below does
> not qualify as a function that includes a prototype:
>
> void foo(a)
> char *a;
> {
> do_something(a);
> }
>
> int main(void)
> {
> foo();
> return 0;
> }


Probably the definition of "function prototype" in 6.2.1p2:

A _function prototype_ is a declaration of a function that
declares the types of its parameters.

The *definition* of foo() declares the type of a; the *declaration*
doesn't.


So where default argument promotions do not apply,
do pre-ansi compilers infer the type in the above example
from 'a', so that they know it is a 'pointer to char'?


Within the function, the declaration of a is visible, so the compiler
knows it's a char*.

For a call, the compiler doesn't know what type of argument the
function expects, so it's up to the caller to pass the right type.
It's similar to what happens with printf-like functions.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 8 '06 #4


j0mbolar wrote On 02/07/06 20:41,:
Which sections in the standard mandate that 'foo' below does
not qualify as a function that includes a prototype:

void foo(a)
char *a;
{
do_something(a);
}

int main(void)
{
foo();
return 0;
}

also, under 6.11.2 of c99, how is it possible
to declare a file scope object with internal linkage
without using 'static'?


Perhaps 6.11.2 is referring to the situation described
in 6.2.2/4:

/* at file scope: */
static int x; /* internal linkage */
...
extern int x; /* internal linkage, obscolescent(?) */

--
Er*********@sun.com

Feb 8 '06 #5

Eric Sosman wrote:
j0mbolar wrote On 02/07/06 20:41,:
Which sections in the standard mandate that 'foo' below does
not qualify as a function that includes a prototype:

void foo(a)
char *a;
{
do_something(a);
}

int main(void)
{
foo();
return 0;
}

also, under 6.11.2 of c99, how is it possible
to declare a file scope object with internal linkage
without using 'static'?


Perhaps 6.11.2 is referring to the situation described
in 6.2.2/4:

/* at file scope: */
static int x; /* internal linkage */
...
extern int x; /* internal linkage, obscolescent(?) */


What would make that obsolescent? And technically,
this would involve the use of 'static' in making it
have internal linkage. It is just that the latter declaration
does not inhibit the former's meaning.

--
j0mbolar

Feb 8 '06 #6

Eric Sosman wrote:
j0mbolar wrote On 02/07/06 20:41,:
Which sections in the standard mandate that 'foo' below does
not qualify as a function that includes a prototype:

void foo(a)
char *a;
{
do_something(a);
}

int main(void)
{
foo();
return 0;
}

also, under 6.11.2 of c99, how is it possible
to declare a file scope object with internal linkage
without using 'static'?


Perhaps 6.11.2 is referring to the situation described
in 6.2.2/4:

/* at file scope: */
static int x; /* internal linkage */
...
extern int x; /* internal linkage, obscolescent(?) */


I meant to set follow-ups to comp.std.c

What do the committee members in comp.std.c
have to say about this?

--
j0mbolar

Feb 8 '06 #7
j0mbolar wrote:
Eric Sosman wrote:
j0mbolar wrote On 02/07/06 20:41,:
Which sections in the standard mandate that 'foo' below does
not qualify as a function that includes a prototype:
void foo(a)
char *a;
{
do_something(a);
}
int main(void)
{
foo();
return 0;
}
Does it *look* to you like there is a prototype in scope?
There is an argument mismatch in any event.
also, under 6.11.2 of c99, how is it possible
to declare a file scope object with internal linkage
without using 'static'?

Perhaps 6.11.2 is referring to the situation described
in 6.2.2/4:
/* at file scope: */
static int x; /* internal linkage */
...
extern int x; /* internal linkage, obscolescent(?) */

What do the committee members in comp.std.c
have to say about this?


Pretty much what Eric said, except we were thinking of
it without the explicit "extern" (same thing).
Feb 9 '06 #8
En news:43***************@null.net, Douglas A. Gwyn va escriure:
also, under 6.11.2 of c99, how is it possible
to declare a file scope object with internal linkage
without using 'static'?
Perhaps 6.11.2 is referring to the situation described
in 6.2.2/4:
/* at file scope: */
static int x; /* internal linkage */
...
extern int x; /* internal linkage, obscolescent(?) */


Pretty much what Eric said, except we were thinking of
it without the explicit "extern" (same thing).


Can you elaborate?

If you mean
static int x;
int x;
I read 6.2.2p5, 2nd sentence as making x of external linkage, and the
combination of both lines is UB by 6.2.2p7.

This text is unchanged since C89 (I thought a DR had added something, so
checked, and turned empty.)
Antoine

Feb 9 '06 #9
En news:11**********************@f14g2000cwb.googlegr oups.com,
j0mbolar va escriure:
also, under 6.11.2 of c99, how is it possible
to declare a file scope object with internal linkage
without using 'static'?

/* at file scope: */
static int x; /* internal linkage */
...
extern int x; /* internal linkage, obscolescent(?) */


What would make that obsolescent?


What: the Standard, the very 6.11.2.

Why: because when you are looking only at the second line (arbitrarily far
from the first), you do not immediately notice that the identifier is not
visible outside this translation unit.

Making this obsolescent is (was really) a free card for the committee to
revoke such a possibility in the future. It is also a strong hint the above
is "bad style."
Antoine

Feb 9 '06 #10
j0mbolar wrote:
Keith Thompson wrote:
"j0mbolar" <j0******@engineer.com> writes:
Which sections in the standard mandate that 'foo' below does
not qualify as a function that includes a prototype:

You should be aware that the following counts as a declaration of
foo():
void foo(a)
while everything from here on in is only part of the definition of
foo(); it's not part of the declaration.
A declaration that is only a declaration, and not a definition, could
be present in one translation unit, while the actual definition of the
function might be in an entirely different translation unit.
char *a;
{
do_something(a);
}

int main(void)
{
foo();
return 0;
}


Probably the definition of "function prototype" in 6.2.1p2:

A _function prototype_ is a declaration of a function that
declares the types of its parameters.

The *definition* of foo() declares the type of a; the *declaration*
doesn't.


So where default argument promotions do not apply,
do pre-ansi compilers infer the type in the above example
from 'a', so that they know it is a 'pointer to char'?


No; they handled such code in pretty much the same way as it's
currently handled. The definition of 'a' that is provided as part of
the definition of foo() has significance only inside the definition of
foo(); it has no effect on the interpretation of calls to foo(). If the
promoted type of an argument is incompatible with the actual type of
the corresponding parameter, you've got trouble; there's no implicit
conversion to the specified type, because in the absence of a
prototype, there is no specified type. There's also no mandatory
diagnostic to warn you of the problem. That's why prototypes were
invented.

Feb 9 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

21 posts views Thread by Headless | last post: by
7 posts views Thread by Alan Illeman | last post: by
2 posts views Thread by Buck Turgidson | last post: by
3 posts views Thread by Michael Shell | last post: by
8 posts views Thread by Jarno Suni not | last post: by
9 posts views Thread by Eric Lindsay | last post: by
14 posts views Thread by Schraalhans Keukenmeester | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.