User: Password:
Subscribe / Log in / New account

Looks like your Pascal knowleadge is lacking

Looks like your Pascal knowleadge is lacking

Posted Jul 15, 2008 23:10 UTC (Tue) by vmole (guest, #111)
In reply to: Looks like your Pascal knowleadge is lacking by khim
Parent article: What Red Hat and Firestar agreed to

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.

(Log in to post comments)

Looks like your Pascal knowledge is lacking

Posted Jul 18, 2008 0:48 UTC (Fri) by giraffedata (subscriber, #1954) [Link]

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.

Looks like your Pascal knowledge is lacking

Posted Jul 18, 2008 11:20 UTC (Fri) by nix (subscriber, #2304) [Link]

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 © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds