Thread: Fixed array

  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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    Then what's wrong with the member array?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    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.

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > 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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 11-08-2011, 11: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, 03: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, 03:06 PM