| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Pascal - C |
12 Apr 96 08:19, Frank Adam wrote to Andrew Clarke:
> So i'm an idiot, what's new?
I'd like to tell you, but not right now.
AC>> procedure wrapper;
AC>> procedure inside;
AC>> begin
AC>> writeln('Hello from the inside.');
AC>> end;
AC>> begin
AC>> writeln('Hello world.');
AC>> end;
AC>> C doesn't support silly stuff like this. I'm not sure if
AC>> it's standard Pascal either. (?)
> But isn't this the same as..
> while(!done)
> {
> while(!wrote)
> {
> printf("hello");
> ...
> }
> printf("hello written");
> ...
> }
> I always thought nesting meant procedures within procedures,am i
> missing something ?
No, the only thing you've done there is show how to nest blocks.
In Pascal (or Borland Pascal, at least) you can define an entire procedure
inside another one, meaning you could have two
functions/procedures with the same name in the same source module, provided
they were enclosed in their own individual "wrapper"
functions/procedures. C doesn't support this, and the closest you'll get
to these sorts of "private" functions is declaring a function as
"static", meaning that it can't be accessed by other modules in
your application, eg.
-+- test1.c -+-
#include
void callAnotherMyFunc(void);
static void myFunc(void)
{
printf("Hello from %s\n", __FILE__);
}
int main(void)
{
myFunc();
callAnotherMyFunc();
return 0;
}
-+- test2.c -+-
#include
static void myFunc(void)
{
printf("Hello from %s\n", __FILE__);
}
void callAnotherMyFunc(void)
{
myFunc();
}
-+-
randy{at}snoopy:/main/home/randy$gcc -o test test1.c test2.c
randy{at}snoopy:/main/home/randy$test
Hello from test1.c
Hello from test2.c
The following won't compile though, since the standard doesn't support it ...
-+- test.c -+-
#include
int main(void)
{
void myFunc(void)
{
printf("Hello from the inside.\n");
}
myFunc();
printf("Hello world.\n");
return 0;
}
-+-
[f:\csource\test]wcl386 test.c
wcc386 TEST.C
TEST.C(6): Error! E1009: Expecting ';' but found '{'
TEST.C(8): Warning! W107: Missing return value for function 'main'
...
Regards
Andrew
--- Msgedsq/2 3.30
* Origin: Blizzard of Ozz, Melbourne, Australia (3:635/727.4{at}fidonet)SEEN-BY: 50/99 78/0 620/243 623/630 632/349 635/503 544 727 637/106 711/401 SEEN-BY: 711/409 410 413 430 808 809 932 934 712/515 713/888 714/906 800/1 SEEN-BY: 7877/2809 @PATH: 635/727 544 50/99 711/808 809 934 |
|
| 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™.