Fixed array

This is a discussion on Fixed array within the C Programming forums, part of the General Programming Boards category; Hi everyone! I need an array inside structure, something like this: Code: struct mystruct { char array[16]; } but the ...

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    20

    Fixed array

    Hi everyone!
    I need an array inside structure, something like this:
    Code:
    struct mystruct {
    char array[16]; 
    }
    but the way, that it doesnt give me pointer, but leaves 16 bytes free space inside structure. In asm i would do like this to get that result:
    Code:
    MYSTRUCT:
    ....
    times 16 db ?
    .....
    END_MYSTRUCT:
    How do I do it in C?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,734
    If you want a member pointer, then define the struct to have a member pointer, e.g.,
    Code:
    struct mystruct {
        char *array;
    };
    But if as you say you want an array, then you have an array, so don't complain "that it doesnt give me pointer" because you got what you asked for.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    20
    That is the point, i dont need pointer, i need it to reserve 16 bytes inside structure.
    something like this:
    Code:
    struct mystruct {
    char 0;
    char 1;
    ...
    char 14;
    char 15;
    }
    Last edited by wirmius; 10-14-2012 at 03:25 AM.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,734
    Then what's wrong with the member array?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    So choose your first answer then!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Sep 2008
    Posts
    200
    Wirmius: Your first code listing of your first post gives you exactly what you've described. Is there a reason you think you're mistaken?
    Programming and other random guff: cat /dev/thoughts > blogspot.com (previously prognix.blogspot.com)

    ~~~

    "The largest-scale pattern in the history of Unix is this: when and where Unix has adhered most closely to open-source practices, it has prospered. Attempts to proprietarize it have invariably resulted in stagnation and decline."

    Eric Raymond, The Art of Unix Programming

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    > That is the point, i dont need pointer, i need it to reserve 16 bytes inside structure.
    An array is NOT A POINTER!

    Arrays and Pointers
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 11-08-2011, 10:29 AM
  2. GCC:Static(fixed-length) array in template class
    By tra86 in forum C++ Programming
    Replies: 9
    Last Post: 06-21-2011, 03:00 PM
  3. Simpson's rule and Trapezoidal rule from fixed array
    By timwonderer in forum C++ Programming
    Replies: 1
    Last Post: 12-02-2010, 02:14 PM
  4. Use vector instead of fixed-size array
    By clegs in forum C++ Programming
    Replies: 19
    Last Post: 09-16-2007, 09:00 PM
  5. what fixed does
    By ssharish in forum C++ Programming
    Replies: 4
    Last Post: 01-24-2005, 02:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21