[32448] in Perl-Users-Digest
Perl-Users Digest, Issue: 3715 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 15 09:09:18 2012
Date: Fri, 15 Jun 2012 06:09:04 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 15 Jun 2012 Volume: 11 Number: 3715
Today's topics:
[OT] C prototypes [was: Perl Protoypes] <ben@morrow.me.uk>
Re: [OT] C prototypes <rweikusat@mssgmbh.com>
Re: [OT] C prototypes <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 14 Jun 2012 19:22:26 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: [OT] C prototypes [was: Perl Protoypes]
Message-Id: <2ompa9-6022.ln1@anubis.morrow.me.uk>
Quoth Michael Vilain <vilain@NOspamcop.net>:
>
> Maybe declaring a prototype was something that C did to keep from having
> to parse the code more than once. That way compile-time errors in the
> same file could be flagged. But I've never written a compiler, so what
> do I know.
In ANSI C prototypes are necessary so the compiler knows what types the
arguments and return value are. If you have a function
void foo (long l);
and you call it like
int i = 1;
foo(i);
the compiler can tell (from looking at the prototype) that it must cast
i from int to long before passing it to the function.
In K&R C, prototypes were neither necessary nor permitted, because it
only ran on machines where all data types were the same length. They
were added to ANSI C when C was ported to other machines, where (say)
int and long might be different lengths, and passing a 16bit int in
place of a 32bit long would make a horrible mess of the stack.
Ben
------------------------------
Date: Thu, 14 Jun 2012 20:46:19 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: [OT] C prototypes
Message-Id: <87k3z98yno.fsf@sapphire.mobileactivedefense.com>
Ben Morrow <ben@morrow.me.uk> writes:
[...]
> In K&R C, prototypes were neither necessary nor permitted, because it
> only ran on machines where all data types were the same length.
This is not true: Even the earliest versions of C had 'char' which was
a byte and int/ pointers which were a (16-bit) word. C also existed on
32-bit systems way before it became standardized.
> They were added to ANSI C when C was ported to other machines, where
> (say) int and long might be different lengths, and passing a 16bit
> int in place of a 32bit long would make a horrible mess of the
> stack.
The way this worked was that 'int' was considered to be 'the universal
type' and all integers smaller than that were promoted to int when
being passed as an argument (similarly, double was supposed to be 'the
universal floating-point type'). Arguments for which these rules were
not sufficient had to be casted to the type expected by the called
routines as part of the call.
------------------------------
Date: Thu, 14 Jun 2012 21:04:47 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: [OT] C prototypes
Message-Id: <vnspa9-ci22.ln1@anubis.morrow.me.uk>
Quoth Rainer Weikusat <rweikusat@mssgmbh.com>:
> Ben Morrow <ben@morrow.me.uk> writes:
>
> > In K&R C, prototypes were neither necessary nor permitted, because it
> > only ran on machines where all data types were the same length.
>
> This is not true: Even the earliest versions of C had 'char' which was
> a byte and int/ pointers which were a (16-bit) word.
True. 'All function parameters and return values' would have been a
better way of expressing what I meant.
Ben
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 3715
***************************************