enum and 2D array declaration

This is a discussion on enum and 2D array declaration within the C Programming forums, part of the General Programming Boards category; Hi All, I'm having some trouble declaring a 2D array using enum members like so: (code has been simplified for ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    2

    Angry enum and 2D array declaration

    Hi All,

    I'm having some trouble declaring a 2D array using enum members like so:

    (code has been simplified for this example)

    Code:
    typedef enum AV_FORMATS_ENUM
    {
        AV_FORMAT_0 = 0,
        AV_FORMAT_1,
        AV_FORMAT_2,
        NUM_OF_AV_FORMATS
    } AV_FORMAT;
    
    typedef enum DECODE_TYPE_ENUM
    {
        DECODE_0 = 0,
        DECODE_1,
        DECODE_2,
        NUM_OF_DECODE_TYPES
    } DXVA_TYPE;
    
    char FormatDecodeMatrix[NUM_OF_AV_FORMATS][NUM_OF_DECODE_TYPES]; <-- problem
    Now, this builds just fine on my local installation of MS Visual Studio 2008, however when I submit on our infrastructure's more stringent build system it says that the 2nd constant, NUM_OF_DECODE_TYPES, isn't declared.

    So of course my questions is, whats wrong with this? NUM_OF_DECODE_TYPES is used in loops all over the code and my intent was that if somebody added a new format the rest of the could should work along with it.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    C90 requires arrays sizes to be constants created with define

    constant variables created with const key word or enum members cannot be used in array declaration
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    2
    Quote Originally Posted by vart View Post
    C90 requires arrays sizes to be constants created with define

    constant variables created with const key word or enum members cannot be used in array declaration
    After putting commas after the last members in the enums, the build system compiled without errors. Based upon what you said in your post, is the behaviour now undefined?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. two dimensional array
    By leisiminger in forum C Programming
    Replies: 12
    Last Post: 03-09-2008, 11:53 PM
  2. Dynamically Allocating a 2D Array.
    By LightsOut06 in forum C Programming
    Replies: 17
    Last Post: 10-09-2005, 12:55 AM
  3. assigning 2d array to type **arr doesn't work
    By scoobasean in forum C++ Programming
    Replies: 7
    Last Post: 02-26-2005, 02:14 PM

Tags for this Thread


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