Skip to content

Instantly share code, notes, and snippets.

@robsbots
Created April 20, 2014 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robsbots/11119276 to your computer and use it in GitHub Desktop.
Save robsbots/11119276 to your computer and use it in GitHub Desktop.
/****************************************************************************
* odd_func.c
*
* Strange function definition test
*
* Can you define one function inside another and have it compile ?
* Apparently you can.
* We can have local functions.......
* Neither of these local function can be called from outside their scope.
*
* compile with 'cc odd_func.c -o odd_func'
***************************************************************************/
#include <stdio.h>
// A normal function predefined
void a_func(void);
// Main as usual
int main(int argc, char* argv[])
{
// Standard etc
printf("Hello world\n");
// Define a new "local" function
void test1(void)
{
printf("Tester function\n");
}
// Call that function defined above
test1();
// Call the normal function
a_func();
// return with no error
return 0;
}
void a_func(void)
{
// Just something to do
printf("a Function\n");
//define another local function
void test1(void)
{
printf("Another Tester function\n");
}
// Call this new local function
test1();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment