Looks like your Pascal knowledge is lacking
Looks like your Pascal knowledge is lacking
Posted Jul 18, 2008 0:48 UTC (Fri) by giraffedata (guest, #1954)In reply to: Looks like your Pascal knowleadge is lacking by vmole
Parent article: What Red Hat and Firestar agreed to
I think the difference between C and Pascal here isn't in the language definition; it's in the culture. C's culture is get-the-job-done and Pascal's is one of mathematical elegance.
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)
[Link]
Looks like your Pascal knowledge is lacking
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.
