473,237 Members | 1,285 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,237 software developers and data experts.

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 1383
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Headless | last post by:
I've marked up song lyrics with the <pre> tag because it seems the most appropriate type of markup for the type of data. This results in inefficient use of horizontal space due to UA's default...
7
by: Alan Illeman | last post by:
How do I set several different properties for PRE in a CSS stylesheet, rather than resorting to this: <BODY> <PRE STYLE="font-family:monospace; font-size:0.95em; width:40%; border:red 2px...
2
by: Buck Turgidson | last post by:
I want to have a css with 2 PRE styles, one bold with large font, and another non-bold and smaller font. I am new to CSS (and not exactly an expert in HTML, for that matter). Is there a way to...
3
by: Michael Shell | last post by:
Greetings, Consider the XHTML document attached at the end of this post. When viewed under Firefox 1.0.5 on Linux, highlighting and pasting (into a text editor) the <pre> tag listing will...
8
by: Jarno Suni not | last post by:
It seems to be invalid in HTML 4.01, but valid in XHTML 1.0. Why is there the difference? Can that pose a problem when such a XHTML document is served as text/html?
7
by: Rocky Moore | last post by:
I have a web site called HintsAndTips.com. On this site people post tips using a very simply webform with a multi line TextBox for inputing the tip text. This text is encode to HTML so that no...
9
by: Eric Lindsay | last post by:
I can't figure how to best display little snippets of shell script using <pre>. I just got around to organising to bulk validate some of my web pages, and one of the problems occurs with Bash...
23
by: Xah Lee | last post by:
The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations Xah Lee, 2006-03-15 Let me summarize: The LISP notation, is a functional notation, and is not a...
14
by: Schraalhans Keukenmeester | last post by:
I am building a default sheet for my linux-related pages. Since many linux users still rely on/prefer viewing textmode and unstyled content I try to stick to the correct html tags to pertain good...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.