Click here to Skip to main content
15,860,861 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
is it syntactically valid to define a function with in another function?
Posted

In C, you cannot do that.
In C++ you can indirectly, e.g.
C++
int f()
{
   struct S {
      int g() { return 1; }
   } s;
   return s.g();
}
You may declare a function within a function (so that it can be used), but it's definition must be placed elsewhere, e.g.
C++
int f()
{
   extern int g();
   return g();
}
...
int g() { return 1; }
Cheers
Andi
 
Share this answer
 
v2
No.

It isn't valid in C, or C++ or C#, or even VB.

You can't even use anonymous delegates in C, so there really, really is no way to do it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900