Skip to content

Instantly share code, notes, and snippets.

@clarkzjw
Created January 1, 2015 12:43
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 clarkzjw/f7400be50c9d9ad68526 to your computer and use it in GitHub Desktop.
Save clarkzjw/f7400be50c9d9ad68526 to your computer and use it in GitHub Desktop.
Nested function is supported as an extension in gcc, but not g++.
#include <stdio.h>
double foo(double a, double b)
{
double square(double a) { return a * a; }
return square(a) + square(b);
}
int main(int argc, char **argv)
{
int a = 2, b = 3;
printf("%lf\n", foo(a, b));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment