Thread: Why does this structure allocate memory?

  1. #16
    Registered User
    Join Date
    Apr 2009
    Posts
    145
    Grumpy is right......

    with additional modification it can work wonders.....
    Code:
    typedef struct{
    	int b;
    	int len;
           statusrecord stRec[];
    } rsp;
    
    
    adding len field, which can take dynamic values.......
    
    rsp *francis;
    
    francis = malloc(sizeof(rsp)+len)

  2. #17
    C++11 User Tux0r's Avatar
    Join Date
    Nov 2008
    Location
    Sweden
    Posts
    135
    Quote Originally Posted by sanddune008 View Post
    Grumpy is right......

    with additional modification it can work wonders.....
    Code:
    typedef struct{
    	int b;
    	int len;
           statusrecord stRec[];
    } rsp;
    
    
    adding len field, which can take dynamic values.......
    
    rsp *francis;
    
    francis = malloc(sizeof(rsp)+len)
    I don't see how that code is valid.

  3. #18
    Registered User
    Join Date
    Apr 2009
    Posts
    145
    yeah its not valid.....I was under the impression this way one can make the structure dynamic..

  4. #19
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by sanddune008 View Post
    yeah its not valid.....I was under the impression this way one can make the structure dynamic..
    In C, the only way to make a "structure dynamic" (i.e. have it resized on demand) is to manually resize the memory associated with it. There is no feature in C that allows such things to happen automatically.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tools for finding memory leaks
    By stanlvw in forum C++ Programming
    Replies: 4
    Last Post: 04-03-2009, 11:41 AM
  2. allocate apecified memory location for a c variable
    By BharathKumar in forum Linux Programming
    Replies: 5
    Last Post: 06-01-2007, 03:47 PM
  3. free memory in structure
    By franziss in forum C++ Programming
    Replies: 22
    Last Post: 01-08-2007, 05:16 PM
  4. Memory handler
    By Dr. Bebop in forum C Programming
    Replies: 7
    Last Post: 09-15-2002, 04:14 PM
  5. Is it necessary to write a specific memory manager ?
    By Morglum in forum Game Programming
    Replies: 18
    Last Post: 07-01-2002, 01:41 PM