簡體   English   中英

Linux kernel 中不允許 Function 返回數組

[英]Function returning array is not allowed in Linux kernel

After cloning the Linux kernel and opening up for example /drivers/md/dm-zero.c in VSCode (with the C CPP extension) gives me an error at the last 3 lines saying: function returning array is not allowed .

當然我知道這不應該是一個錯誤,因為我只是克隆並且沒有調整任何東西。 C CPP 擴展中是否有應設置的設置?

謝謝!

編輯:標題具有誤導性:我知道這與 kernel 本身無關,但我想指出 VSCode 抱怨已經寫在 Linux Z6FF9F4444AC4816342F4412B5E16 源代碼中的內容

Edit2:具體錯誤在這 3 行中: function 返回數組不允許 C/C++(91)

MODULE_AUTHOR("Jana Saout <jana@saout.de>");
MODULE_DESCRIPTION(DM_NAME " dummy target returning zeros");
MODULE_LICENSE("GPL");

例如MODULE_AUTHOR擴展為

#define __MODULE_INFO(tag, name, info)                    \
    static const char __UNIQUE_ID(name)[]                 \
        __used __section(".modinfo") __aligned(1)         \
        = __MODULE_INFO_PREFIX __stringify(tag) "=" info

我在 Ubuntu 20.04 中使用 GCC

/drivers/md/dm-zero.c

...

在最后 3 行給我一個錯誤

我假設你的意思是跟隨?

MODULE_AUTHOR("Jana Saout <jana@saout.de>");
MODULE_DESCRIPTION(DM_NAME " dummy target returning zeros");
MODULE_LICENSE("GPL");

這些是宏,如果您挖掘並查找它們的定義,它們絕對有效。 由於無法找到定義,您得到的錯誤是 VSCode 及其 C/C++ 擴展(無論是什么)的本地錯誤。

vscode github repo 中的這條評論為我解決了這個問題。 基本上需要在c_cpp_properties.json文件中添加一些顯式包含路徑和編譯器參數。

"includePath": [
  "/usr/src/linux-headers-5.4.0-39-generic/arch/x86/include",
  "/usr/src/linux-headers-5.4.0-39-generic/arch/x86/include/generated",
  "/usr/src/linux-headers-5.4.0-39-generic/include",
  "/usr/src/linux-headers-5.4.0-39-generic/arch/x86/include/uapi",
  "/usr/src/linux-headers-5.4.0-39-generic/arch/x86/include/generated/uapi",
  "/usr/src/linux-headers-5.4.0-39-generic/include/uapi",
  "/usr/src/linux-headers-5.4.0-39-generic/include/generated/uapi",
  "/usr/src/linux-headers-5.4.0-39-generic/ubuntu/include",
  "/usr/lib/gcc/x86_64-linux-gnu/9/include"
],
"compilerArgs": [
  "-nostdinc",
  "-include", "/usr/src/linux-headers-5.4.0-39-generic/include/linux/kconfig.h",
  "-include", "/usr/src/linux-headers-5.4.0-39-generic/include/linux/compiler_types.h"
]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM