I recently came across an example of C-structure initialization, which was explained by this question .
What I do not understand is a recursive definition; this is from MicroPython / objtype.c
typedef struct _mp_obj_type_t mp_obj_type_t; const mp_obj_type_t mp_type_type = {
Fields specified .<some_field> , I understand (see link in the first sentence).
But about "recursive" initialization?
There are other examples in MicroPython code that use this syntax:
const mp_obj_type_t pyb_led_type = { { &mp_type_type }, <-- SAME SYMBOL AS ABOVE .name = MP_QSTR_LED, .print = led_obj_print, .make_new = led_obj_make_new, .locals_dict = (mp_obj_t)&led_locals_dict, };
This makes sense: the pyb_led_type structure pyb_led_type initialized with the default values specified in struct mp_type_type , and some fields change from the default value.
But what about const mp_obj_type_t mp_type_type ?
The string mp_type_type defaults to., mp_type_type ., ???
The pre-processed output is identical to .c .
What's going on here?
There are several structure fields
struct _mp_obj_type_t { // A type is an object so must start with this entry, which points to mp_type_type. mp_obj_base_t base; // The name of this type. qstr name; // Corresponds to __repr__ and __str__ special methods. mp_print_fun_t print; ... }; struct _mp_obj_base_t { const mp_obj_type_t *type MICROPY_OBJ_BASE_ALIGNMENT; }; typedef struct _mp_obj_base_t mp_obj_base_t;