How to initialize all members of an array to the same value?

后端 未结 23 1905
清歌不尽
清歌不尽 2020-11-21 04:34

I have a large array in C (not C++ if that makes a difference). I want to initialize all members of the same value.

I could swear I

23条回答
  •  一整个雨季
    2020-11-21 05:19

    Here is another way:

    static void
    unhandled_interrupt(struct trap_frame *frame, int irq, void *arg)
    {
        //this code intentionally left blank
    }
    
    static struct irqtbl_s vector_tbl[XCHAL_NUM_INTERRUPTS] = {
        [0 ... XCHAL_NUM_INTERRUPTS-1] {unhandled_interrupt, NULL},
    };
    

    See:

    C-Extensions

    Designated inits

    Then ask the question: When can one use C extensions?

    The code sample above is in an embedded system and will never see the light from another compiler.

提交回复
热议问题