Not logged in
Log in now
Create an account
Subscribe to LWN
LWN.net Weekly Edition for May 23, 2013
An "enum" for Python 3
An unexpected perf feature
LWN.net Weekly Edition for May 16, 2013
A look at the PyPy 2.0 release
The settlement itself reads somewhat like a Pascal program; one must start toward the bottom and read it in reverse.
+1 for QOTW.
What Red Hat and Firestar agreed to
Posted Jul 15, 2008 19:19 UTC (Tue) by darwish07 (subscriber, #49520)
I did not work on Pascal before.
Does Mr. Corbet means something like below C program where lots of internal function code
exist and the main() is thrown at the end (where you have to scroll down till main() code to
understand the big picture) ?
// lots of code
// lots of code
if () func3(0;
Posted Jul 15, 2008 19:30 UTC (Tue) by vmole (guest, #111)
Yeah, that's it exactly. Pascal didn't allow forward references/decarations/definitions, so you were basically forced into this style of coding.
Looks like your Pascal knowleadge is lacking
Posted Jul 15, 2008 20:09 UTC (Tue) by khim (subscriber, #9252)
Pascal DOES have forward definitions. Always had. There are exactly ONE exception: main program goes to the end. All other procedures and functions can be moved around as you wish, but main program goes to the end - always.
Posted Jul 15, 2008 23:10 UTC (Tue) by vmole (guest, #111)
I freely admit my Pascal knowledge is long forgotten, but in my defense, I offer this quote from Brian Kernighan's Why Pascal is Not My Favorite Language: "Since the original Pascal was implemented with a one-pass compiler, the language believes strongly in declaration before use. In particular, procedures and functions must be declared (body and all) before they are used." I should have remembered also his note that there was a "forward" declaration, with some restrictions.
Looks like your Pascal knowledge is lacking
Posted Jul 18, 2008 0:48 UTC (Fri) by giraffedata (subscriber, #1954)
In both languages, you have to declare a subroutine before you can call it. If you don't want to fully define it, you at least need a prototype.
(It's the reason I always write C upside down -- I hate writing anything twice).
In Pascal, the custom is that if subroutine bar supports foo, you code bar inside foo. You can do that in C too, but it's nearly unheard of. If you do that, in either language, you must define bar before the procedural code of foo; to do otherwise would be like declaring variables at the bottom of a subroutine.
Pascal does have a "program" concept that C doesn't have (a C program is just a collection of zero or more peer subroutines; only the linker knows how to turn them into a program), which means at least one line of main code does have to go at the bottom of the main file of a program, even if you otherwise eschew the nested subroutine convention.
Posted Jul 18, 2008 11:20 UTC (Fri) by nix (subscriber, #2304)
Actually nested functions aren't valid in C. They're a GCC extension, and
while I might wish they were in the Standard (give us closures, too,
please!) they're not.
Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds