Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   When did K&R function declarations become obsolete? (http://www.velocityreviews.com/forums/t806806-when-did-k-and-r-function-declarations-become-obsolete.html)

Alan Mackenzie 12-10-2011 06:23 PM

When did K&R function declarations become obsolete?
 
I think we can say that K&R function declarations are truly obsolete. In
~20 years of hacking C, I've only seen very old code which uses them.

Presumably these declarations are still widely used in compiler validation
suites but nowhere else.

Approximately when did they become obsolete, i.e. not used at all for new
code?

[Context: I'm writing documentation for Emacs's C Mode.]

--
Alan Mackenzie (Nuremberg, Germany).


88888 Dihedral 12-10-2011 06:40 PM

Re: When did K&R function declarations become obsolete?
 
The _fastcall, _cdecl, _pascall were used everywhere.

Do you really know how c functions are called in the run time ?


Kaz Kylheku 12-10-2011 06:41 PM

Re: When did K&R function declarations become obsolete?
 
On 2011-12-10, Alan Mackenzie <acm@muc.de> wrote:
> I think we can say that K&R function declarations are truly obsolete. In
> ~20 years of hacking C, I've only seen very old code which uses them.


These declarations are still a feature of the 1999 C language, but marked as
obsolescent ISO 9899:1999:

6.11.7 Function definitions

1 The use of function definitions with separate parameter identifier and
declaration lists (not prototype-format parameter type and identifier
declarators) is an obsolescent feature.

(If you want to know about the current draft status of this, Google it up;
I dont' know.)

> Presumably these declarations are still widely used in compiler validation
> suites but nowhere else.


They likely appear in some nonzero but impossible to quantify amount of legacy
code.

Some open source programs still use old style definitions, coupled with
prototype declarations.

E.g.:

int func PROTO(( char *, int ));

/* ... */

int func(a, b)
char *a;
int b;
{
/*...*/
}

Are these programs rare? In some sense, yes, but in fact we do not have to go
far to find an example.

For instance, oh, the GNU C Library (glibc):

http://sourceware.org/git/?p=glibc.g...ob;f=io/open.c

Snippet retrieved Sat Dec 10 10:40:55 PST 2011:

/* Open FILE with access OFLAG. If OFLAG includes O_CREAT,
a third argument is the file protection. */
int
__open (file, oflag)
const char *file;
int oflag;
{
int mode;

if (file == NULL)
{
__set_errno (EINVAL);
return -1;
}

> Approximately when did they become obsolete, i.e. not used at all for new
> code?


This is impossible to know, without a crystal ball that peers into
what everyone on the planet is coding.

Ian Collins 12-10-2011 06:49 PM

Re: When did K&R function declarations become obsolete?
 
On 12/11/11 07:40 AM, 88888 Dihedral wrote:
> The _fastcall, _cdecl, _pascall were used everywhere.


The what?

> Do you really know how c functions are called in the run time ?


What on Earth is this nonsense in reply to?

--
Ian Collins

Ben Pfaff 12-10-2011 06:49 PM

Re: When did K&R function declarations become obsolete?
 
88888 Dihedral <dihedral88888@googlemail.com> writes:

> The _fastcall, _cdecl, _pascall were used everywhere.


....in Windows and perhaps MS-DOS code and nowhere else, and are
completely orthogonal to the transition from K&R to
prototype-style function declarations.
--
Ben Pfaff
http://benpfaff.org

Jens Thoms Toerring 12-10-2011 09:16 PM

Re: When did K&R function declarations become obsolete?
 
Alan Mackenzie <acm@muc.de> wrote:
> I think we can say that K&R function declarations are truly obsolete. In
> ~20 years of hacking C, I've only seen very old code which uses them.


> Presumably these declarations are still widely used in compiler validation
> suites but nowhere else.


> Approximately when did they become obsolete, i.e. not used at all for new
> code?


When I started using C in 1989 they were still quite common to be
seen in code I was looking at but that dropped significantly during
the following decade and I hardly ever have seen code using them
written in this millenium. So my very personal guess is that most
people use the "new" form since at least about 1995. But then I did
programming nearly exclussively under UNIX, things might be diffe-
rent for platforms were "modern" compilers weren't available that
easily. And, of course, people having to cater for the very smal-
lest common denominator (i.e. systems were no C89 compliant com-
piler exists) still have to use them in one form or another (as
the example Kaz came up with might be an example for).

If this is for the emacs C mode then, since the standard still
requires support for the "old way" (even though it might be de-
clared as obsolete) I would think it prudent not to throw it
out completely.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de

Keith Thompson 12-10-2011 09:48 PM

Re: When did K&R function declarations become obsolete?
 
Alan Mackenzie <acm@muc.de> writes:
> I think we can say that K&R function declarations are truly obsolete. In
> ~20 years of hacking C, I've only seen very old code which uses them.
>
> Presumably these declarations are still widely used in compiler validation
> suites but nowhere else.
>
> Approximately when did they become obsolete, i.e. not used at all for new
> code?
>
> [Context: I'm writing documentation for Emacs's C Mode.]


I'm not aware that they've ever become completely obsolete in that
sense. One poster in comp.std.c, Jun Woong, is apparently still using
them (unnecessarily IMHO, but I can see his point); see Message-ID
<923cd9a6-c717-478e-89f9-d04d03b7205c@p2g2000vbj.googlegroups.com>,
<http://groups.google.com/group/comp.std.c/msg/819a7f3553366ef8>.

They've been *obsolescent* since C89 (see 6.9.4 and 6.9.5 in the
C90 standard, presumably 3.9.4 and 3.9.5 in the C99 standard),
and remain so in the latest C201X draft.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Ralph Spitzner 12-11-2011 03:16 AM

Re: When did K&R function declarations become obsolete?
 
Alan Mackenzie wrote:
> I think we can say that K&R function declarations are truly obsolete. In
> ~20 years of hacking C, I've only seen very old code which uses them.


Sorry, but having read the thread so far I still don't get it.
Are you guys talking about declarations, or implementations ?

After all to avoid an implicit declaration as 'int (void)'
(or (int), for that matter) one would have to declare in some.h like:

char *myfunc(char *);

then implement it as either

char *
myfunc(char *thestring)
{
....
}

or old

char *myfunc(thestring)
char *thestring;
{
....
}

What am I missing here, a proper C course ? :-P

-rasp

ralph 12-11-2011 04:27 AM

Re: When did K&R function declarations become obsolete?
 
On Sat, 10 Dec 2011 18:23:19 +0000 (UTC), Alan Mackenzie <acm@muc.de>
wrote:

>I think we can say that K&R function declarations are truly obsolete. In
>~20 years of hacking C, I've only seen very old code which uses them.
>
>Presumably these declarations are still widely used in compiler validation
>suites but nowhere else.
>
>Approximately when did they become obsolete, i.e. not used at all for new
>code?
>
>[Context: I'm writing documentation for Emacs's C Mode.]


As Mr. Thompson pointed out the closest to an "official" date would be
C89, however K&R fell out of common use long before that. Most C
compilers I used by the early 80s offered vendor specific
implementations that supported the "ANSI style", though there wasn't
any official 'ANSI' yet.

The only C compiler I remember by name and version is Microsoft C 3.0
(XENIX) and it was what we would call fully "ANSI compatible" in 1985.
Other platform compilers I used earlier all had the ANSI-style option
available before then. And we all quickly jumped at using it whenever
it was available.

[The reason I'm so vague is because back then just about every box
came with its own "C compiler" or managment sprang for some 3rd-party
"development package" - the fine-print contained a copyright of some
sort but you seldom paid much attention to it, unless there was a
difference in some obscure library. And then you were likely to code a
conditional compile for the "VAX-C", or for accounting's "XENIX-BOX",
etc.]

I've been trying to remember when I last was forced to use pure K&R
and I think it was a DEC VAX/VMS project in 1983???

-ralph

Keith Thompson 12-11-2011 05:48 AM

Re: When did K&R function declarations become obsolete?
 
Keith Thompson <kst-u@mib.org> writes:
[...]
> They've been *obsolescent* since C89 (see 6.9.4 and 6.9.5 in the
> C90 standard, presumably 3.9.4 and 3.9.5 in the C99 standard),
> and remain so in the latest C201X draft.


Sorry, I meant 3.9.4 and 3.9.5 in the ANSI C89 standard. (ISO C90
described the same language, but renumbered the sections.)

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


All times are GMT. The time now is 04:45 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.