-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sat, Oct 28, 2017 at 11:35:59PM +0200, Thomas Schmitt wrote: > Hi, > > it seems that gcc just hates a static function declaration inside a function. > > This code (without any include) > > static int bla(int x) > { > return (x != 1); > } > int main() > { > static int bla(int x); > return(bla(0)); > } > > yields > > t.c: In function ‘main’: > t.c:19:13: error: invalid storage class for function ‘bla’ > static int bla(int x); > ^ > > The compile time error vanishes if i move the declaration out of the function, > or if i remove the "static", or if i remove the declaration completely > (as it is surplus in both programs, mine and Fred's). > > I wonder what gives "static int bla(int x);" such a different meaning inside > and outside a function. To my naive but long tested understanding, both > should differ only by their scope.
Nested function definitions are a gcc-ism (please don't take this as a pejorative term: personally I do like gcc-isms, but one should know when one's making use of them). Here's more about it. And yes, static or extern don't work with them. But auto does. And g++ doesn't like them (I guess there's a reason): https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html Cheers - -- t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEUEARECAAYFAln1nYAACgkQBcgs9XrR2kYC3gCWJ3TRCDRRDzgT4HxqNYLp28w2 awCeO7tWrqxn3yLKF48daNLizuWa+NU= =o1BZ -----END PGP SIGNATURE-----