microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.46k stars 1.53k forks source link

cpptools can't recognize far/near keyword #4356

Open Lennon925 opened 4 years ago

Lennon925 commented 4 years ago

捕获

error shows: "expected a ';' "

sean-mcmanus commented 4 years ago

Our parser has near/far support disabled (same as the VS default). How exactly are you getting your compiler to support that? i.e. what compiler/flags? I see it used for 16-bit compilation with older Microsoft compilers.

qk-li commented 4 years ago

I am using VS Code to edit the code of an old project on 80186 based µC and have the same errors with far/near pointers. It is no wonder that I can't complie my project with modern compilers but I really like the features of VS Code such as IntelliSense

bobbrow commented 4 years ago

A workaround would be to add "near=" and "far=" to the "defines" array in c_cpp_properties.json

github-actions[bot] commented 3 years ago

This feature request is being closed due to insufficient upvotes. When enough upvotes are received, this issue will be eligible for our backlog.

hmaon commented 3 years ago

I've also just run into this while working with a codebase targeting the venerable NEC V30 chip, using the Watcom compiler..

github-actions[bot] commented 3 years ago

This feature request has received enough votes to be added to our backlog.

Colengms commented 3 years ago

We should check if this is something easy for the IntelliSense parser to support.

Phyioa commented 3 years ago

@bobbrow Your suggestion to do this

    "C_Cpp.default.defines": [
        "near=",
        "far="
    ]

does not solve the issue for me, unfortunately.

Does anyone have another suggestions? I am still getting the expected a ';' or expected a ')' error.

This probably also causes types not being resolved in other places.

sean-mcmanus commented 3 years ago

@Phyioa Do you have a c_cpp_properties.json or compileCommands or configurationProvider set? Those could be overwriting the C_Cpp.default.defines. You could tell if the define is being recognized by hovering it.

image

Phyioa commented 3 years ago

@sean-mcmanus Yes, it seems like I do have a c_cpp_properties.json, which I didn't know of. It has the following contents right now.

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${default}"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.14393.0",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe",
            "intelliSenseMode": "windows-msvc-x64"
        }
    ],
    "version": 4
}

I have neither compileCommands nor configurationProvider set.

Hovering some of the fars I found in the code does not indicate that the defines are recognized.

Any tips on how to proceed? Thanks for your help so far! <3

sean-mcmanus commented 3 years ago

@Phyioa Add "${default}" to your list of defines in c_cpp_properties.json (see https://code.visualstudio.com/docs/cpp/customize-default-settings-cpp for more info).

Phyioa commented 3 years ago

@sean-mcmanus Oh my god! You are a life savior! Thank you so much. <3 Works like a charm now! :)

hmaon commented 3 years ago

is it OK to add the defines to c_cpp_properties.json directly, like this?

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE",
                "near=",
                "far="
            ],
            "windowsSdkVersion": "10.0.18362.0",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-msvc-x64"
        }
    ],
    "version": 4
}

It seems to work fwiw.