Assigning a variable length array within a structure.

Discussion in 'C Programming' started by mr_guy99493, Feb 4, 2011.

  1. mr_guy99493

    mr_guy99493

    Joined:
    Feb 4, 2011
    Messages:
    1
    Hi

    Id like to put a pointer to an array within a struct. Id also like to define the contents of that array at compile time, in a similar way to the assignment of strings. Ive tried every combination that i can think of, but cant get it to work. The arrays have differing lengths, but since they're known at compile time it shouldnt be a problem. It works for strings, so there should be no difference right?

    Code:
    typedef struct
    {
    	char*	String;
    	int*	uintArray_arr;
    } S_Struct;
    
    
    S_Struct S1 = 
    {
        "Description",
        {INT1,INT2,INT3}
    }
    
    S_Struct S2 = 
    {
        "Description that is longer",
        {INT1,INT2,INT3,EXTRA_INT}
    }
    
    Any ideas?? I can make it work by defining separate arrays, then pointing the pointers at them, but its not pretty code. It would be great if I could do it similar to the way shown here.
    mr_guy99493, Feb 4, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Cox [Microsoft MVP]

    Re: Assigning contents within HTML tag to string variable.

    Ken Cox [Microsoft MVP], Aug 5, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    887
    tonymjohn
    Aug 7, 2004
  2. Adam Warner

    Flexible array member + variable length array

    Adam Warner, Feb 3, 2005, in forum: C Programming
    Replies:
    10
    Views:
    784
    S.Tobias
    Feb 10, 2005
  3. Andrew Smallshaw

    Variable structure, constant length allocations

    Andrew Smallshaw, Nov 10, 2008, in forum: C Programming
    Replies:
    5
    Views:
    327
    James Kuyper
    Nov 11, 2008
  4. weston
    Replies:
    1
    Views:
    239
    Richard Cornford
    Sep 22, 2006
  5. 4Ankit@gmail.com
    Replies:
    1
    Views:
    202
Loading...

Share This Page