Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

bobatefrei

Sub function in C++, ANSI hack?

This topic is 6194 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is this code compatible with ANSI C++? Witch compiler support it? void MyFunction() { struct Local { static void RecursiveFunction(int i) { if (i > 0) RecursiveFunction(i-1); } }; Local::RecursiveFunction(6); } PS: I found it on www.flipcode.com

Share this post


Link to post
Share on other sites
Advertisement
It looks pretty ANSI compatible, and GCC/MinGW32 2.95.2 has no complains about it.

There's no real point to it though. It's not a real "sub-function" (don't remember what they're really called) like those you can write in for example Pascal, since Local::RecursiveFunction won't be able to access any variables that are local to MyFunction. A 'true' "sub-function" should be able to access data in the syntactically enclosing function, through the stack frame pointers.

Edited by - Dactylos on August 6, 2001 11:28:53 AM

Share this post


Link to post
Share on other sites
Yeah, it''s perfectly ANSI.

I happen to think that such things are useful sometimes when you need to perform a repetitive task in a function and want to make it obvious that the task is only used there. The alternative is to use a macro or a separate function declared static. Just like goto, this kind of trickery has its place.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!