Thread: Structs as argument

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    As long as you're aware that the names don't have to be the same (they can be if you want, but it can lead to confusion).

    As to the question, I have no idea why you would expect passing a struct to a function to be different from passing a struct to a function. (EDIT: But I suppose I should say that you are correct: passing a struct to a function is not different from passing a struct to a function, so your code is fine.)

  2. #2
    Registered User
    Join Date
    Aug 2011
    Posts
    31
    oh. I saw this example about char* pointers, hence the question about structs

    Code:
    int my_new(char **obj) {
        *obj = malloc(somesize);
    }
    and then call this from your function like this:

    Code:
    char *obj;
    
    my_new(&obj);
    
    /* work on obj */
    
    free(obj)
    Hence was wondering if it applies to structs

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Template Argument inside the Argument of a Function Declaration
    By manasij7479 in forum C++ Programming
    Replies: 3
    Last Post: 06-11-2011, 05:53 AM
  2. [ noob question ] Help with structs within structs
    By Riverfoot in forum C Programming
    Replies: 3
    Last Post: 04-26-2011, 07:24 PM
  3. Passing Structs Into An Array Of Structs.
    By TheTaoOfBill in forum C Programming
    Replies: 3
    Last Post: 10-07-2010, 09:38 AM
  4. Replies: 3
    Last Post: 03-31-2009, 12:34 PM
  5. passing structs & pointers to structs as arguments
    By Markallen85 in forum C Programming
    Replies: 6
    Last Post: 03-16-2004, 07:14 PM