June 12th, 2003, 06:56 PM
C and C++
I'm a new C leaner and i'm using DEc c++ as a compiler. Sometimes i got confused between C and C++ and my textbook doest mention that problem.
Can you guys tell me about defineing one function inside another function. E.g
If i compile it with C, the compiler gives a warning but still runs the prob. But with C++, it does not.
June 12th, 2003, 07:13 PM
I'm not sure about C, but I know that in C++ you cannot define a function within another function. It specifically states this as an error when you compile the program. What is the warning that you get when you compile it in C?
June 12th, 2003, 09:30 PM
In the future please use an appropriate subject title. See the "How to Post" sticky thread at the top of this forum for more information.
June 12th, 2003, 09:33 PM
I'm sorry. Ididnt mean making it sticky.
June 12th, 2003, 09:37 PM
It's not a problem, this was just a gentle nudge not to do so again. The thread I pointed you to will give you some good guidelines as to how to post an appropriate subject title.
You can also follow the links in my signature for more information.
Also, just curious, but why would you want to declare/define one function inside of another one?
June 12th, 2003, 09:39 PM
I just got that idea when studying the scope of functions and variables.
June 12th, 2003, 09:42 PM
Typically it isn't a really good idea. Hence the reason why you get errors/warnings from it.
June 13th, 2003, 12:49 PM
Neither language, C nor C++, permits functions within functions.
June 13th, 2003, 01:23 PM
Yeah, thats what I thought. As it was brought up before, where would be the purpose in that? You can either delare function prototypes before he main func, or simply write the entire function above and not declare anything.
June 13th, 2003, 02:52 PM
So how can I limit only one function can call one specific function by not defining it within the other.
June 13th, 2003, 02:59 PM
I'm not sure I follow. But if I do, you can define it above, and then call it only from the function that you want to use it.
June 13th, 2003, 03:14 PM
Perhaps you can describe more clearly what it is you're trying to do - just what, rather than how. I can think of ways to limit access to a function but I'm not sure that it'd achieve what you're after without understanding your needs better.