identifier "__transaction_atomic" is undefined C/C++(20)

344 Views Asked by At

I am using vscode 1.75.1, the C/C++ microsoft extension installed, and developing on Lubuntu 22.04 LTS with gcc version 11.3.0. When attempting to use software transactional memory (STM) in gcc with the transaction expression denoted by __transaction_atomic, vscode does not recognize the expression and gives the following problems (these are not errors in compilation, just vscode detected problems):

identifier "__transaction_atomic" is undefined C/C++(20)

expected a ';'C/C++(65)

The vscode suggests fixing the problem by editing the include path for C/C++ properties file; however, since STM expressions are a feature of the gcc compiler, I am not sure how that would help. Any suggestions on how to fix this?

Here is some simple code that causes the problem (since it is an issue with intellisense and not with program logic). Note that the code compiles and runs without issues.

// gcc -fgnu-tm example_stm.c 
int main() {
    __transaction_atomic { /*an atomic operation*/ }
    return 0;
}

I have the following configuration information in my projects .vscode file:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_POSIX_C_SOURCE=199309L"
            ],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu99",
            "cppStandard": "c++14",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

Note that I have tried changing the C standard in the c_cpp_properties.json file to C11, and other versions; however, that did not fix the problem.

1

There are 1 best solutions below

0
joeldorado On

The -fgnu-tm flag is only available on systems that support Transactional Memory, such as some Intel processors. You should check if your system supports that for compiling.

For VSCode, while I can't prove it, my guess is that the IDE is incapable of recognizing __transaction_atomic because it isn't running on a system that supports that compiler flag. You might need to switch systems or disable that specific error.