Nested Functions in C - Best Practices

Posted by Justin Ethier on Stack Overflow See other posts from Stack Overflow or by Justin Ethier
Published on 2010-03-18T02:52:03Z Indexed on 2010/03/18 3:01 UTC
Read the original article Hit count: 459

Filed under:
|

I just realized a function may be defined inside another function in C:

void main(){
  int foo(){ return 2; };
  printf("%d\n", foo());
}

Besides being a neat trick, the useful thing about this is that the inner function is private to the outer function. But... is that a good enough reason to do this in a "real-world" application? What are the best practices for using this syntax?

© Stack Overflow or respective owner

Related posts about c

    Related posts about best-practices