Newbi Hel/newbi question

This is a discussion on Newbi Hel/newbi question within the C++ Programming forums, part of the General Programming Boards category; Thanks!!! I"ll try that...

  1. #16
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77
    Thanks!!! I"ll try that

  2. #17
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Originally posted by gamer4life687
    yes there is a effiency difference. in memory.
    Could you elaborate please?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #18
    Registered User
    Join Date
    Aug 2003
    Posts
    44
    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

  4. #19
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    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.
    That would depend on the compiler, I expect.

  5. #20
    Registered User
    Join Date
    Aug 2003
    Posts
    44
    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

  6. #21
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77
    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?

  7. #22
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    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

  8. #23
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    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.
    I think I know what you're trying to say here, but, what exactly does the bold bit say?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  9. #24
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    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.

  10. #25
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    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.
    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.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  11. #26
    Registered User
    Join Date
    Aug 2003
    Posts
    44
    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

  12. #27
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Cheers.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  13. #28
    verbose cat
    Join Date
    Jun 2003
    Posts
    209
    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?

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21