Question

Here are (some of) the structures that I am using; they are in a .h file:

struct rss_s {
    Radio_types device_type;    // Its device_type which is defined by the typedef above Radio_Types
    char * device_info;      // some thing about the radio NAV/COM/etc.
    char * device_model;     // the Manufactures part/model number.
    char * device_serial;    // the device's serial number..
    int power_48v;           // power to the unit..
    int power_400hz;
    int panel_lamps;         // turn off or on the Panel Lamps only
    void * radio_info;
};

typedef struct tuner_s {    // when we talk about 'sub-radios' we are really saying how many tuners are there??
    char * device_name;    // OS-name
    int frequency[tuned];
    int power;
    int dial_lamp;
    int fd[ ];      // file descriptors
}tuner;

//// 614L8 ::= C614L8

typedef enum Lp_Sw_614L8 { OFF_loop, LEFT, RIGHT, SLEW_LEFT, SLEW_RIGHT } loopsw_614L8;
typedef enum Mo_Sw_614L8 { OFF_614L8, ADF, ANT, LOOP } modesw_614L8;

struct radio_s_614L8 {
    loopsw_614L8 loop_sw_614L8;
    modesw_614L8 mode_sw_614l8;
    int sw_band;
    int sw_bfo;
    int meter;
    tuner * Tuner;
    int tuners;
};      

Now file main.c, which has all of the normal includes:

// Radio 614L8<br>

static struct radio_s_614L8 radio_614L8 = { { .Tuner = tuner_614L8, .tuners = DIM( tuner_C_614L8 ) } };
static tuner tuner_614L8 = { { .device_name = "/dev/TBD", }  };

static struct rss_s radios[] = {
    { C614L8, "ADF", "614L8", "8384", & radio_C_614L8,},};

// now comes the normal main()

The errors that I have:

  • error: field name not in record or union initializer
  • error: (near initialization for ‘radio_614L8.loop_sw_614L8’)
  • error: ‘tuner_614L8’ undeclared here (not in a function)
  • error: field name not in record or union initializer
  • error: (near initialization for ‘radio_614L8.loop_sw_614L8’)
  • error: ‘tuner_C_614L8’ undeclared here (not in a function)
  • error: field name not in record or union initializer
  • error: (near initialization for‘tuner_614L8.device_name’)
  • error: ‘radio_C_614L8’ undeclared here (not in a function)

  • Was it helpful?

    Solution

    You currently have:

    static struct radio_s_614L8 radio_614L8 = { { .Tuner = tuner_614L8, .tuners = DIM( tuner_C_614L8 ) } };
    static tuner tuner_614L8 = { { .device_name = "/dev/TBD", }  };
    

    You need:

    static tuner tuner_614L8 =  { .device_name = "/dev/TBD", };
    static struct radio_s_614L8 radio_614L8 = { .Tuner = &tuner_614L8, .tuners = 1 };
    

    You can't refer to a variable like tuner_614L8 until you've defined or declared it. You shouldn't try to make a non-array into an array, either. You do need to take the address of the tuner, too. You don't show DIM, but I'm assuming it is more or less one of these two equivalent macros:

    #define DIM(x)  (sizeof(x)/sizeof(*(x)))
    #define DIM(x)  (sizeof(x)/sizeof((x)[0]))
    

    On further analysis, your tuner structure contains a flexible array member. You can't sensibly allocate such variables as static or global variables, or as automatic variables; you have to allocate them with malloc() and relatives to get a non-empty array.

    However, with that caveat in mind, this code compiles:

    typedef enum Radio_types { C614L8 } Radio_types;
    enum { tuned = 5 };
    
    typedef struct tuner_s
    {
        char *device_name;
        int frequency[tuned];
        int power;
        int dial_lamp;
        int fd[];
    } tuner;
    
    typedef enum Lp_Sw_614L8 { OFF_loop, LEFT, RIGHT, SLEW_LEFT, SLEW_RIGHT } loopsw_614L8;
    typedef enum Mo_Sw_614L8 { OFF_614L8, ADF, ANT, LOOP } modesw_614L8;
    
    struct radio_s_614L8
    {
        loopsw_614L8 loop_sw_614L8;
        modesw_614L8 mode_sw_614l8;
        int sw_band;
        int sw_bfo;
        int meter;
        tuner *Tuner;
        int tuners;
    };
    
    static tuner tuner_614L8 = { .device_name = "/dev/TBD", };
    static struct radio_s_614L8 radio_614L8 = { .Tuner = &tuner_614L8, .tuners = 1 };
    
    struct rss_s
    {
        Radio_types device_type;
        char *device_info;
        char *device_model;
        char *device_serial;
        int power_48v;
        int power_400hz;
        int panel_lamps;
        void *radio_info;
    };
    
    struct rss_s radios[] =
    {
        { C614L8, "ADF", "614L8", "8384", 0, 0, 0, &radio_614L8, },
    };
    
    Licensed under: CC-BY-SA with attribution
    Not affiliated with StackOverflow
    scroll top