Thread: Allocating functions to an array of function pointers inside a struct

  1. #16
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Quote Originally Posted by tabstop View Post
    I think you may be mistaken on what a struct is. A struct is not a thing. A struct is what a thing would look like, if it were to exist. You have to create an object to actually have something. So:
    Code:
    struct hey_a_struct {
        int numbers[10];
    }
    
    /* at this point I have nothing at all */
    int main(void) {
    struct hey_a_struct object; /*now I have something */
    for (int i = 0; i < 10; i++) {
        object.numbers[i] = i*i;
    }
    Completely wrong. The first definition of the struct does indeed reserve the memory for it. It is usable.
    struct hey_a_struct object; will define a second struct with the same shape.

  2. #17
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    The HP store called, those first two letters in your name need to be returned.

  3. #18
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Sorry. My mistake. Who would do such a thing as "define" a struct in this way. (I'm used to putting its name at the end in which case it would make sense.)
    Or else use typedef. I get confused whether the name is just after 'struct', or at the end, vs. when using typedef.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. array inside struct
    By tat in forum C Programming
    Replies: 15
    Last Post: 11-13-2007, 12:36 PM
  2. initializing char array inside a struct
    By panos in forum C Programming
    Replies: 6
    Last Post: 06-01-2007, 06:43 PM
  3. allocating array of pointers
    By l2u in forum C++ Programming
    Replies: 1
    Last Post: 06-01-2006, 10:11 AM
  4. Dynamicly allocating an array of pointers
    By kzar in forum C Programming
    Replies: 2
    Last Post: 05-05-2005, 04:50 PM
  5. Replies: 4
    Last Post: 09-12-2001, 02:05 PM