[問題] struct如何使用extern

看板C_and_CPP (C/C++)作者時間10年前 (2015/08/24 17:34), 編輯推噓3(303)
留言6則, 6人參與, 最新討論串1/1
問題(Question): 我的平台有coreA和coreB,各有main(),在main()內宣告的變數皆使用 L1 記憶體, (平台記憶體有L1、L2_SRAM、L3_SDRAM) 想在L2_SRAM.h下宣告struct 而在system.h下extern struct,讓在其他.c檔只要#include system.h 就可以使用此struct...但出現錯誤如下, 請問有人知道我的問題出在哪裡嗎...?懇請告知謝謝 <L2_SRAM.h> struct my_struct { int x; int y; }; <system.h> extern struct my_struct MYSTRUCT; <main.c> MYSTRUCT.x = 10; //編譯出現錯誤 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.251.198.39 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1440408894.A.D68.html

08/24 17:59, , 1F
你要不要在L2_SRAM.h加一行 my_struct MYSTRUCT;
08/24 17:59, 1F

08/24 18:09, , 2F
要了解什麼是變數的宣告式、什麼是變數的定義式
08/24 18:09, 2F

08/24 19:20, , 3F
ADI blackfin?
08/24 19:20, 3F

08/24 22:13, , 4F
system.h 有 include "L2_SRAM.h" 嗎?
08/24 22:13, 4F

08/24 22:55, , 5F
1.2F意見+1
08/24 22:55, 5F

08/25 12:44, , 6F
extern的意思跟你想的正好相反
08/25 12:44, 6F
文章代碼(AID): #1LskK-re (C_and_CPP)
文章代碼(AID): #1LskK-re (C_and_CPP)