Thanks!!! I"ll try that
Could you elaborate please?Originally posted by gamer4life687
yes there is a effiency difference. in memory.
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
When you have a function header plus body before main(), it gets it a memory address, just as a prototype would, then it "preprocesses" the body (saves the process in memory without actually executing it).
When you call it in main it then excutes the body. If the function was prototyped and the body comes after main(), the when it's called is loads the process and executes at the same time.
These two methods don't really do anything different. The same steps take place. The only difference is: when you don't prototype, the actual process (body) of the function stays in memory a little longer than it has to.
As for code readability: always, always prototype. It's a good practice to get into.
Check out all my dimensions:
Height, width, and for a limited time only... Depth!
-sb
That would depend on the compiler, I expect.Originally posted by Wick
These two methods don't really do anything different. The same steps take place. The only difference is: when you don't prototype, the actual process (body) of the function stays in memory a little longer than it has to.
Seems the logical order. But, who knows? I was just reiterating someone much more keen on the subject than I am.
Check out all my dimensions:
Height, width, and for a limited time only... Depth!
-sb
Originally posted by alpha
The deprecated headers are headers like iostream.h, stdlib.h. they should be iostream and cstdlib. there are more, and more info should be able to found in the faq
I got that error. How do I fix it?
Change you #include statements to include <iostream> and <cstdlib> (no .h) instead...And use the std namespeace:
Code:using namespace std;
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
I think I know what you're trying to say here, but, what exactly does the bold bit say?Originally posted by Wick
When you call it in main it then excutes the body. If the function was prototyped and the body comes after main(), the when it's called is loads the process and executes at the same time.
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
It means the function will only load and execute if it's called. If you put the function's body before main, the function would load before we even call and sit in memory.
What I meant was, Wick's post actually makes no sense grammatically. I understand how protoypes work now, but I just wanted to see what he meant to write.Originally posted by alphaoide
It means the function will only load and execute if it's called. If you put the function's body before main, the function would load before we even call and sit in memory.
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
I meant to say "then when it's called it loads the process and executes at the same time."
tired typos
Check out all my dimensions:
Height, width, and for a limited time only... Depth!
-sb
Cheers.
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
Sorry to bump but I was hoping someone could verify this for me as I don't have alot of programming experience under my belt.
Previous posts indicate that the order of the source code has an effect on the efficiency of the program, i.e. putting the function definition before main causes it to "sit" until it's called while putting a prototype first and the definition after will allow the function to be loaded and executed at the same time. Wouldn't this only possibly affect compile time of the program?
Once the compiler is finished, the full function will be loaded into memory when the program is executed anyway and "sit" until it's called. Unless you are working with .DLL's or something else that only loads relevant code at runtime when it needs it, the entire program needs to sit in memory at all times so the program execution can "jump" to it as appropriate.
Inline functions do need to have the definition before the code that calls them, but that's not quite what the previous posts are describing (and in fact kind of contradicts...)
Am I correct or is this truly an optimization to consider once the program is working?