Thread: complex data structure - please help

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

    Smile complex data structure - please help

    I am working on a data structure, and I have difficulty understand it. Please see the following:


    Code:
    #define SAA7134_BOARD_KWORLD_ATSC115    0
    
    struct saa7134_board {
    	char                          *name;
    	unsigned int            audio_clock;
    
    	/* input switching */
    	unsigned int            gpiomask;
    	struct saa7134_input    inputs[SAA7134_INPUT_MAX];
    	struct saa7134_input    radio;
    	struct saa7134_input    mute;
    	
    	/* peripheral I/O */
    	unsigned int            i2s_rate;
    	unsigned int            has_ts;
    	enum saa7134_video_out  video_out;
    
    	/* i2c chip info */
    	unsigned int		radio_type;
    	unsigned char		tuner_addr;
    	unsigned char		radio_addr;
    
    	unsigned int            tda9887_conf;
    	unsigned int            tuner_config;
    	unsigned int 		tuner_type;
    	
    	/* peripheral I/O */
    	enum saa7134_mpeg_type  mpeg;
    	unsigned int            vid_port_opts;
    };
    
    
    struct saa7134_board saa7134_boards[] = {
    
                    [SAA7134_BOARD_KWORLD_ATSC115] = {
    		.name           = "Kworld ATSC115",
    		.audio_clock    = 0x00187de7,
    		.tuner_type     = TUNER_PHILIPS_TUV1236D,
    		.radio_type     = UNSET,
    		.tuner_addr     = ADDR_UNSET,
    		.radio_addr     = ADDR_UNSET,
    		.tda9887_conf   = TDA9887_PRESENT,
    		.mpeg           = SAA7134_MPEG_DVB,
    		.inputs         = {{
    			.name = name_tv,
    			.vmux = 1,
    			.amux = TV,
    			.tv   = 1,
    		},{
    			.name = name_comp1,
    			.vmux = 3,
    			.amux = LINE2,
    		},{
    			.name = name_svideo,
    			.vmux = 8,
    
    			.amux = LINE2,
    		}},
    	}
    };

    I have difficulty understand the last data structure, especially the "[SAA7134_BOARD_KWORLD_ATSC115] = {", what does this mean?

    Any help will be appreciated.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Do you see the define at the top? That means that everytime you see SAA7134_BOARD_KWORLD_ATSC115, it means "0".

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    10

    Smile

    I saw that, but not sure I understand that. Is that equivalent to:

    Code:
    struct saa7134_board saa7134_boards[0] = {
    		.name           = "Kworld ATSC115",
    		.audio_clock    = 0x00187de7,
    		.tuner_type     = TUNER_PHILIPS_TUV1236D,
    		.radio_type     = UNSET,
    		.tuner_addr     = ADDR_UNSET,
    		.radio_addr     = ADDR_UNSET,
    		.tda9887_conf   = TDA9887_PRESENT,
    		.mpeg           = SAA7134_MPEG_DVB,
    		.inputs         = {{
    			.name = name_tv,
    			.vmux = 1,
    			.amux = TV,
    			.tv   = 1,
    		},{
    			.name = name_comp1,
    			.vmux = 3,
    			.amux = LINE2,
    		},{
    			.name = name_svideo,
    			.vmux = 8,
    
    			.amux = LINE2,
    		}}
    };
    Thanks again.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    No, it's a very literal replacement by the pre processor. Only the words inside the square brackets, would be replaced by 0.

    The brackets were not included in the #define.

    I'm not sure what sense that makes, but there you have it.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So you're sort of asking two questions there. The 0 wouldn't go there, it would go literally where the ALLCAPSCONSTANT was. But there's a compiler extension/C99 feature that allows you to initialize in that not-quite-as-awkward-as-it-looks syntax:
    Code:
    int array_with_not_many_elements[200] = 
        { [0] = 5, [17] = 3, [185] = 4 };

  6. #6
    Registered User
    Join Date
    Mar 2010
    Posts
    10
    Now I got it. Thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data structure for storing serial port data in firmware
    By james457 in forum C Programming
    Replies: 4
    Last Post: 06-15-2009, 09:28 AM
  2. pthread question how would I init this data structure?
    By mr_coffee in forum C Programming
    Replies: 2
    Last Post: 02-23-2009, 12:42 PM
  3. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  4. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-08-2007, 12:24 AM
  5. Dynamic Data Structure -- Which one is better?
    By Yin in forum C++ Programming
    Replies: 0
    Last Post: 04-10-2002, 11:38 PM