TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: steven pasztor
from: Paul Edwards
date: 1996-04-24 00:07:48
subject: Re: Pascal - C

sp>> And is it possible to do something like Pascal's nested
sp>> procedures?

PE> Ah, this one is not possible, at least with C.  However, you may
PE> get what you really want, by using separate source files, and making
PE> the functions in them "static", ie internal-visibility only.

sp>  Hmmm...?  I must claim ignorance of such things...  How is it done and 
sp> what does it do?

If you write a function, e.g.

void foo(void)
{
    printf("fred nurk!\n");
}

and put it in a file, e.g. foo.c, then you have another file, e.g. 
main.c, and you go foo(), there is no problem, because foo() will
be found.

However, had you gone:

static void foo(void)
{
    printf("fred nurk!\n");
}

Then your "main.c" would have failed to link, because it couldn't
find foo.  That is because "static" makes foo() hidden from all
people outside the *file*.  As opposed to Pascal which does the
same thing outside the *procedure*.  However, you will probably
find that putting that procedure in a file by itself, is no harm
at all.  Depends what you're REALLY trying to do.  BFN.  Paul.

P.S. Decent C compilers will even take the static functions and
inline them if appropriate, since they know they're not being
used from outside.
@EOT:

---
* Origin: X (3:711/934.9)

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.