473,793 Members | 2,810 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 3614
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.mu n.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_Keit h) 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.mu n.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********@yah oo.com) (cb********@wor ldnet.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
16947
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 create a parameter query in a stored procedure, but how do I use the result set of a parameter query in a select query (in the same or another sp)? In short, if a select query contains a result table that is generated as a parameter query, how do I...
5
11114
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 The queries are nested, and they both use parameters. In MS Acccess the management of nested queries with parameters is so easy (implicit declaration of parameters, transmission of parameters from main query to nested query)
7
5676
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 invalid, but we are doing no such thing... After banging my head on the wall for a bit I noticed that the two stored procedures that are experiencing this behavior are procedures that are called from within another procedure (they're not both...
0
2966
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 EXIT HANDLER FOR SQLEXCEPTION
2
10630
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 execute the top-level Stored Procedure, it executes succesfully, but without any resultset. ========================================================== CREATE PROCEDURE sp_executesql(sqltxt CLOB(2M))
2
1908
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 idea to have all stored procedures that we might need (ETL, additional transformers, etc) for this project and any other project written in Java as opposed to SQL/P? Does anyone have any number or experience in terms of performance differences?
18
7661
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: RHINO.CALLED01: 18: SQL0104N An unexpected token "<cursor declaration>" was found following "". Expected tokens may include: "<SQL statement>". LINE NUMBER=18 SQLSTATE=42601 Here is the source code for the proc; line 18 is the line that begins
2
2353
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 with nested procedures. That is, a procedure (or function) can contain local procedures (and functions). Procedures can be nested arbitrarily deep. The scoping rules for procedure names (i.e., the ability to call
1
1536
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. Where as when I run them all together as Nested proces (calling one in another as sub-procedures) Log file is growing pretty bad like 25 to 30GB.. and finally getting kicked after running disk space. This process is running around 3hrs on a SQL...
0
9671
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10433
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10212
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10161
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5436
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4112
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2919
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.