簡體   English   中英

C 中的 Vs 代碼警告

[英]Vs code warnings in C

我對如何在我的系統中配置VS Code以顯示警告感到困惑:

  • C/C++ IntelliSense,調試(已安裝)
  • 問題 windows 工作正常,它快速顯示標識符未定義變量等錯誤。
  • 以下代碼不顯示任何警告:

// C 代碼:

#include <stdio.h>

int main()
{
    int a;
    printf("%d", a);
  
}

在這種情況下,我應該得到: 'a' is used uninitialized,我怎樣才能得到所有警告?

我找到了答案,在文件 task.json 中添加“-Wall”如果文件 task.json 不是由 VS Code 自動生成的,則可以手動添加:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe build active file",
            "command": "C:\\msys64\\mingw64\\bin\\gcc.exe",
            "args": [
                "-Wall",
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

在此處輸入圖像描述

暫無
暫無

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

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