Thread: Inline??

  1. #1
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879

    Question Inline??

    Hey everyone, this one's got me baffled. I had a bit of code that I kept on using over and over in the same program, so I figured it would be simpler and easier just to make it a function:
    Code:
    void backToConnect(HWND dialogToEnd);
    {
         server->release();
         delete server;
         server = new Socket;
         dlgState = DS_CONNECT;
         EndDialog(dialogToEnd, 0);
    }
    For some reason, when I replaced the exact same lines of code with a call to the function, I would always get a stack overflow. Then I made the function inline, and it worked fine again. Is there any quick and obvious reason that I'm not seeing, or is it something very code-specific?

    **EDIT**
    Hmm, never mind... now, it doesn't work with the inline either. Still, any ideas? I thought the code should function in the same way since server and dlgState are global variables, but apparently it doesn't...
    Last edited by Hunter2; 08-09-2003 at 11:09 AM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  2. #2
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    A guess...

    Maybe you have to pass a pointer to server...

    server->release(); // It doesn't look like server is a global variable.

    Can you have a global object???

    But I dunno... I would have thought if was something like that, you'd have gotten a compile error (?)

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Hmm... well, I have at the top of my code, before my WinMain():
    Socket* server;

    And everything else (if I coded everything like I thought I did) accesses server as a global variable. Besides, why would it cause a stack overflow? Or did I totally get what you're saying wrong...
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    The first server is created like so:
    server = new Socket; //At the top of WinMain()

    And also, should I be ignoring the "stack overflow"? I thought that usually means infinite recursion or something, but I don't see why changing existing line-by-line code into a function call should cause infinite recursion when the original code didn't.

    **EDIT**
    Oh, forgot to mention, but at this point it IS supposed to delete the old socket and create a new one, since this gets called when the server has disconnected from the client and the client gets the 0-byte or SOCKET_ERROR recv.
    Last edited by Hunter2; 08-09-2003 at 01:12 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Well, I hit debug when it crashed, and popped up the "call stack" window, and here is my analysis:

    Code:
    if(serverShutdown()) //crash
    {
         MessageBox(hWnd, "Connection to server lost.", "Error", MB_OK);
         backToConnect(hWnd);
    }
    
    serverShutdown() calls:
    server->hasData() which calls:
    select() //crash
    Also, once in a while it will simply not crash but infinitely pop up messageboxes that say "Connection to server lost" (which SOUNDS like infinite recursion to me), after which right-clicking "My Computer" and going to properties results in a message saying "Access to the specified device, path, or file is denied", and Notepad has "not enough memory" to run while MSVC++ does... Any ideas?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  6. #6
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Heh, well, any ideas as to the cause? Or do you need more code or something, or just lost interest?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Just a couple of thoughts..

    Are you sure your backToConnect() function actually ends? Maybe put some additional debugging in at the start and end of the function to prove that it is.

    Does it release the socket correctly here:
    server->release()
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    2

    Thumbs up

    HI nothing happened with ur code except this that ur program crashes the whole pc system so..........
    it isssss sugeested that. ........ u r doin good job continue it

  9. #9
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Salem,
    I haven't gotten time yet, but I'll be sure to read up on those articles.

    Hammer,
    Thanks for the suggestion, I'll try that in a little while, but for the moment I've switched back to my old line-by-line code and am just about to finish my overall project, and I don't feel like stopping to debug that part at this moment. I'll let you know what I find when I do try it, though. Also, release() SHOULD properly release the socket, and I've never had a problem with it before (**Well, I did but I fixed it right away).

    Sana Ali,
    Thank you, I think I will take your advice and finish my program.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  10. #10
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Ahh... Hammer, I tried what you suggested and I logged the start and end of the function, but it never showed up. I also got my program to log every call of LoginProc(), and under LoginProc(), every time serverShutdown() returns true. I got 535 LoginProc() calls and serverShutdown() returned true 484 times, but in between, no backToConnect() start or end. Should I start searching for my compiler install CD?

    Salem, I read the first article, but I don't really get the point. Are you saying to check for garbage 0xCDCDCDCD and 0xDDDDDDDD values, or are you trying to suggest that I use the various ASSERT_'s, or that I use static_cast, or that I use DYNAMIC_DOWNCAST, or that I should use ON_NOTIFY_REFLECT_EX instead of ON_NOTIFY_REFLECT, and return TRUE from my handler?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. When to inline your *tors
    By Angus in forum C++ Programming
    Replies: 43
    Last Post: 10-29-2008, 03:38 PM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM
  4. bit shifting
    By Nor in forum C++ Programming
    Replies: 9
    Last Post: 08-08-2003, 11:55 AM
  5. Replies: 5
    Last Post: 09-17-2001, 06:18 AM