Structures and unions

This is a discussion on Structures and unions within the C Programming forums, part of the General Programming Boards category; I'm trying to define an array of structure type CHAR_INFO with 2000 elements, and a union in the same time ...

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    182

    Structures and unions

    I'm trying to define an array of structure type CHAR_INFO with 2000 elements,
    and a union in the same time of an array of 8000 characters.

    CHAR_INFO has already a union inside:
    Code:
    typedef struct _CHAR_INFO { // chi  
        union {                /* Unicode or ANSI character  */ 
            WCHAR UnicodeChar; 
            CHAR AsciiChar; 
        } Char; 
        WORD Attributes;       // text and background colors 
    } CHAR_INFO, *PCHAR_INFO;
    I am not able to figure how should I declare the structure with a union to
    have the same area of 8000 bytes usable in both array mode and struct mode.

    If I declare an array of structure type CHAR_INFO:
    Code:
    CHAR_INFO area_to_write[2000];
    Where do I put the union to use the same area for an array of 8000 characters?

    Thanks for any help you can give me.
    Last edited by frktons; 07-30-2010 at 07:42 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    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: 6
    Last Post: 09-21-2008, 05:18 PM
  2. Structures, Unions and Classes
    By Makoy in forum C++ Programming
    Replies: 2
    Last Post: 02-23-2004, 02:57 PM
  3. Structures - Unions
    By AProg in forum C Programming
    Replies: 16
    Last Post: 05-27-2003, 01:43 AM
  4. Unions and Structures
    By C-Struggler in forum C Programming
    Replies: 4
    Last Post: 03-06-2003, 11:28 AM
  5. Structures and unions
    By Paninaro in forum C Programming
    Replies: 6
    Last Post: 06-21-2002, 02:35 PM

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