473,508 Members | 2,303 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

nested procedures and the C language


Hello,

I am curious as to why the designers of C did not include support for
Pascal-like nested procedures. I guess that it's because nested procedures
in C would not buy you much other than marginally cleaner namespaces, and
then again C has a static keyword for limiting the scope of functions to
a file, which is not quite the same, but seems enough for all practical
purposes. Anyone care to either agree or disagree?

Regards,

Neil

Nov 13 '05 #1
5 3597
Neil Zanella wrote:
I am curious as to why the designers of C did not include support for
Pascal-like nested procedures. I guess that it's because nested procedures
in C would not buy you much other than marginally cleaner namespaces, and
then again C has a static keyword for limiting the scope of functions to
a file, which is not quite the same, but seems enough for all practical
purposes. Anyone care to either agree or disagree?


This is Frequently Asked Question number 20.24

http://www.eskimo.com/~scs/C-faq/q20.24.html

Nov 13 '05 #2
Neil Zanella <nz******@cs.mun.ca> writes:
I am curious as to why the designers of C did not include support for
Pascal-like nested procedures. I guess that it's because nested procedures
in C would not buy you much other than marginally cleaner namespaces, and
then again C has a static keyword for limiting the scope of functions to
a file, which is not quite the same, but seems enough for all practical
purposes. Anyone care to either agree or disagree?


I suspect part of the reason is that disallowing nested procedures
makes the compiler's job easier, something that was probably more
important when the language was being designed than it is now. The
problem is references to variables in enclosing procedures. For
example (in hypothetical C syntax):

void outer(void)
{
int outer_var = 1;

void inner(void)
{
int inner_var = outer_var;
}
}

Assuming a stack implementation, the reference to outer_var in inner()
requires digging some variable distance down the stack, depending on
the current state of the call stack. (Imagine that inner() is
recursive.)

I think Algol supports nested procedures so there was precedent for
the idea, but it wasn't thought to be worth the extra effort.

--
Keith Thompson (The_Other_Keith) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #3
# I am curious as to why the designers of C did not include support for
# Pascal-like nested procedures. I guess that it's because nested procedures
# in C would not buy you much other than marginally cleaner namespaces, and
# then again C has a static keyword for limiting the scope of functions to
# a file, which is not quite the same, but seems enough for all practical
# purposes. Anyone care to either agree or disagree?

Because Fortran didn't. C is mixture of Fortran and Jovial and a sprinkling
of Algol 68. The stack display and static link were well understood.

--
Derk Gwen http://derkgwen.250free.com/html/index.html
I ASSURE YOU WE'RE OPEN!
Nov 13 '05 #4
Neil Zanella writes:
I am curious as to why the designers of C did not include support for
Pascal-like nested procedures. I guess that it's because nested procedures
in C would not buy you much other than marginally cleaner namespaces, and
then again C has a static keyword for limiting the scope of functions to
a file, which is not quite the same, but seems enough for all practical
purposes. Anyone care to either agree or disagree?


I see it (The C way) as the natural view of the world as seem by an assembly
language programmer.
Nov 13 '05 #5
Keith Thompson wrote:
Neil Zanella <nz******@cs.mun.ca> writes:
I am curious as to why the designers of C did not include support
for Pascal-like nested procedures. I guess that it's because
nested procedures in C would not buy you much other than
marginally cleaner namespaces, and then again C has a static
keyword for limiting the scope of functions to a file, which is
not quite the same, but seems enough for all practical purposes.
Anyone care to either agree or disagree?


I suspect part of the reason is that disallowing nested procedures
makes the compiler's job easier, something that was probably more
important when the language was being designed than it is now.


In Pascal, which was originally designed to have a single source
file and no separate compilation facilities, the feature was very
attractive for proper localization. In C, with the separate
compilations, it is much less necessary inasmuch as there are
other methods of limiting scope.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
16928
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can...
5
11102
by: ahokdac-sql | last post by:
Hi, I'm adapting access queries to sql server and I have difficulties with the following pattern : query1 : SELECT * FROM Query2 WHERE A=@param1 query 2: SELECT * FROM Table2 WHERE B=@param2 ...
7
5655
by: Anthony Robinson | last post by:
Have been encountering an odd issue. Every now and again, certain packages of stored procedures just become invalid. I'm aware that dropping or altering an underlying table would render a package...
0
2941
by: Dmitry Tolpeko | last post by:
Hello, Could anybody please explain me why DB2 z/OS 8.1 fails on the simple procedure below: Error: DSNHSMS2 LINE 12 COL 6 NESTED COMPOUND STATEMENTS NOT ALLOWED It failes on DECLARE...
2
10570
by: Twan Kennis | last post by:
Question: How do I pass a returning resultset from a nested Stored Procedure (which opens a cursor including option "WITH RETURN TO CALLER") as a returning resultset from it's own? When I...
2
1891
by: Rafael Faria | last post by:
Hi All, We are starting a large data warehousing project using DB2 8.2 on AIX. There is a direction to move any new internal development to Java and a question was raised: Would it be a good...
18
7592
by: Rhino | last post by:
I am having a problem with a nested SQL Procedure on DB2 V8.2.1 on Windows. This simple-looking proc is giving me this error message when I try to build it in the Development Center: ...
2
2337
by: Quinnie | last post by:
Hi, I have a homework assignment that I'm so confused and really need help with. Here's the description, any help would be appreciated. Thanks! Assume we have a statically-scoped language...
1
1519
by: sasachi sachi sachi | last post by:
Hi there, I have a data manipulation process written in a Nested Stored procedure that have four levels deeper. When I run these individual procedures individually they all seems to be fine....
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7495
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5052
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.