www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/06/13/17:00:29

Message-ID: <39469F22.1F361A30@earthlink.net>
From: Martin Ambuhl <mambuhl AT earthlink DOT net>
Organization: Nocturnal Aviation
X-Mailer: Mozilla 4.73 [en] (Win95; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Simple question: Subfunctions
References: <394693AA DOT 32CB056C AT gmx DOT de>
Lines: 55
Date: Tue, 13 Jun 2000 20:51:31 GMT
NNTP-Posting-Host: 63.23.128.163
X-Complaints-To: abuse AT earthlink DOT net
X-Trace: newsread2.prod.itd.earthlink.net 960929491 63.23.128.163 (Tue, 13 Jun 2000 13:51:31 PDT)
NNTP-Posting-Date: Tue, 13 Jun 2000 13:51:31 PDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com


Hanno Stehling wrote:
> 
> Hi,
> 
> I'm just teaching myself c++ and I have a question about functions:
> 
> in Turbo Pascal it is possible to create subfunctions like
> 
> procedure normal_function;
>   procedure subfunction;
>   begin
>     do_something;
>   end;
> begin
>   subfunction;
> end;
> 
> Is this also possible in c++?

There is a bit of danger in answering in this newsgroup, but here is a go

1) The standard C and C++ languages do not support functions declared except
at file scope.  It is an error to declare one inside another.  Most C and C++
programmers don't miss such things.

2) GCC *does* provide for this as an extension.  It is explained in your
documentation, even to some of the implementation details.  If you ever might
need to port your code to a non-GCC implemenation, all such code would need to
be rewritten.  Even though the GCC documentation thumbs its nose at this
possibility, some of us work in the real world.

3) The class structures and templating functionality available in C++ should
make whatever need you have for this fairly small.  Hundreds of thousands of C
programmers do quite well without embedded functions; the additional
flexibility of the C++ syntax makes them even less useful.

4) Almost all programmers when introduced to a new leanguage try to make it
fir into the categories of the ones they know.  This is almost always an
error.  Importing ideas from other languages should wait until you have
learned the new language on its own terms.  As it happens, the Pascal program
structure is quite horrid.  It is probably good that GCC allows this
particular feature, but should be saved for situations in which it has a real
purpose.  There are worse things in Pascal, most of which people migrating
from Pascal to C or C++ think they miss.  I dread your asking about those.


-- 
Martin Ambuhl	mambuhl AT earthlink DOT net

What one knows is, in youth, of little moment; they know enough who
know how to learn. - Henry Adams

A thick skin is a gift from God. - Konrad Adenauer

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019