Most elegant way to share a C array

后端 未结 4 507
暗喜
暗喜 2021-01-18 22:01

I have to turn back to (embedded) C after some lengthy time with C++, and have the following problem:

I have a source module which is included a lot of times, let\'s

4条回答
  •  甜味超标
    2021-01-18 22:39

    What you have is the canonical way to do it: have an extern declaration in the header file, and define the variable in the .c file.

    my array will be an undefined symbol in worker.c

    No, it won't. Your code will compile and link just fine.

提交回复
热议问题