Thread: Tiny question about structs.

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    6

    Tiny question about structs.

    So I have this function that takes a pointer to a struct as one of its arguments. Everything works like a charm. The problem is as folows:
    The struct that gets its reference passed to the named function values are only initiated for a short time (or only in one funktion), the struct itselft is global so that shouldnt be a problem.

    Anyone got any pointers (pun intended)?

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Yes, show some code that will illustrate what you are trying to do

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    6
    Ok, here goes, IŽll post a shorter version of quasi code. The real version is a bit to big.

    Code:
    typedef struct thing {
      char foo[50];
      char bar[50];
    }
    
    struct test thething;
    
    insert_values_into_thing(struct *thingie) {
    strcpy(thingie->foo, "ksksk");
    ..
    }
    
    int main windowsfunction {
    
    insert_values_into_thing(&thething);
    
    
    }
    
    BOOL CALLBACK windowcallbackfunc(..) {
    
    /*This is where the problem lies, even if thing (that is global) has values earlier in the 
    execution here its totaly blank, and the following message box displays absolutely nada.*/
    
    MessageBox(NULL,thing.foo,...);
    
    }
    
    do_something_with_thing(struct  *thing ) {
    ..
    
    }

    I hope that made any sense

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Ok try to reproduce the error in a short program and then post it. Honestly without seeing the actual code its a crap shoot of what the problem is.
    Of course one question is why is it global if you are going to be passing it around via parameters.

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    6
    Lol, found the problem. Wasnt some thing about structs that I hadnt heard about. Just me overwriting it due to it being global. He. Sorry to waste your time. Thanks for your help though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structs question
    By BigFish21 in forum C Programming
    Replies: 25
    Last Post: 04-23-2008, 09:57 PM
  2. a question on pointers, structs and arrays
    By onefootswill in forum C Programming
    Replies: 3
    Last Post: 12-06-2007, 01:27 AM
  3. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM