Vscode-cpptools: identifier "NULL" is undefined

Created on 4 Oct 2018  Â·  14Comments  Â·  Source: microsoft/vscode-cpptools

Issue Type: Bug

I do not know from when on anytime I type NULL the reporter says this. Everything seemed to be okay before.
My c_cpp_properties.json is pasted here, if required.

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include",
                "/usr/include/c++/8.2.1/tr1",
                "/usr/include/linux"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

Extension version: 0.19.0
VS Code version: Code 1.27.2 (f46c4c469d6e6d8c46f268d1553c5dc4b475840f, 2018-09-12T07:11:15.873Z)
OS version: Linux x64 4.18.10-arch1-1-ARCH


System Info

|Item|Value|
|---|---|
|CPUs|Intel(R) Atom(TM) CPU Z3735F @ 1.33GHz (4 x 601)|
|GPU Status|2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: disabled_software
video_decode: unavailable_software
video_encode: unavailable_software
webgl: enabled
webgl2: enabled|
|Load (avg)|1, 1, 1|
|Memory (System)|1.89GB (0.13GB free)|
|Process Argv|/opt/visual-studio-code/code|
|Screen Reader|no|
|VM|0%|


Language Service investigate more info needed

Most helpful comment

Met the same issue

All 14 comments

New discovery that if there are many NULLs in a file, only the first NULL is reported.
2018-10-05_05 18 17_1366x738_scrot
2018-10-05_05 18 38_1366x738_scrot

Also getting this same issue.

Can you enable Debug logging and share what the include path resolves to for your source file? (search for "include:" in the Output window)

I also confirm this issue.

If I specify a path that contains stddef.h & stdbool.h (I used /usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include/ in this example) in the includePath list, it actually removes the true/false error, but not the NULL definition error. Here is my C/C++ log:

cpptools/didChangeFolderSettings
terminating child process: 16018
still alive, killing...
not exited yet. Will sleep for 1 seconds and try again
Closing the communication channel.
Shutting down IntelliSense server: /home/alexis/Projets/Decagon/src/main.c
  Folder: /usr/local/include/ will be indexed
  Folder: /usr/include/ will be indexed
  Folder: /home/alexis/Projets/Decagon/ will be indexed
Checking for syntax errors: file:///home/alexis/Projets/Decagon/src/main.c
cpptools/didChangeFolderSettings
Unable to resolve include path: /usr/lib/modules/4.18.16-arch1-1-ARCH/build/include/linux/include
sending compilation args for /home/alexis/Projets/Decagon/src/main.c
  include: /usr/include/linux
  include: /usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include
  include: /usr/include/c++/8.2.1
  include: /usr/include/c++/8.2.1/x86_64-pc-linux-gnu
  include: /usr/local/include
  include: /usr/include
  include: /usr/include/c++/8.2.1/tr1
  other: --gcc
  other: --gnu_version=80100
  stdver: --c99
  intelliSenseMode: gcc
queue_update_intellisense for files in tu of: /home/alexis/Projets/Decagon/src/main.c
cpptools/didChangeFolderSettings
terminating child process: 16165
errorSquiggles count: 4
cpptools/didChangeFolderSettings
cpptools/didChangeFolderSettings
cpptools/didChangeFolderSettings

I tried to manually define the NULL macro, and it indeed understand the line:
Manual macro definition works

I was curious to see the contents of /usr/include/linux/stddef.h:
Not VSCode's fault?
I also checked the contents of /usr/lib/gcc/x86_64-pc-linux-gnu/<version>/include/stddef.h, searched the NULL macro definition, and see to my surprise that it was grayed out:
Weird

I assume so that IntelliSense does not properly parse if directives and thus does not declare the NULL macro.

@m03d, based on your log it looks like you don't have compilerPath set in your c_cpp_properties.json or the extension was unable to find a compiler to query so that the system include path/defines could be set properly. Can you share what you have in that configuration file?

@bobbrow I do have compilePath set in c_cpp_properties.json. Here is my configuation file for my current workspace:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "/usr/include/**",
                "/usr/local/include/**",
                "/usr/include/linux/",
                "${workspaceRoot}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c99",
            "intelliSenseMode": "gcc-x64",
            "browse": {
                "path": [
                    "${workspaceRoot}"
                ]
            }
        }
    ],
    "version": 4
}

@m03d You should remove the system includes, i.e. "/usr/...". That is probably breaking things due to incorrect ordering.

I found that when I open a new folder and start coding typing #include <stdio.h>, it will report cannot open source file "stdarg.h" (dependency of "stdio.h") and suggest me to add "/usr/include/c++/8.2.1/tr1" to includePath:
2018-10-27_03 43 26_518x164_scrot
2018-10-27_03 36 06_1366x768_scrot

But after adding, this problem happens.

C/C++ log before adding:

workspace/didChangeConfiguration
IntelliSense Engine = Default.
The extension will use the Tag Parser for IntelliSense when #includes don't resolve.
Autocomplete is enabled.
Error squiggles are enabled.
File exclude: **/.git
File exclude: **/.svn
File exclude: **/.hg
File exclude: **/CVS
File exclude: **/.DS_Store
File exclude: **/.vscode
Search exclude: **/node_modules
Search exclude: **/bower_components
Search exclude: **/.vscode
textDocument/didOpen
cpptools/queryCompilerDefaults
Attempting to get defaults from compiler found on the machine: '/usr/bin/gcc'
terminating child process: 6931
terminating child process: 6934
terminating child process: 6936
terminating child process: 6938
terminating child process: 6940
terminating child process: 6942
terminating child process: 6944
terminating child process: 6946
terminating child process: 6948
cpptools/activeDocumentChange
cpptools/textEditorSelectionChange
textDocument/documentSymbol
textDocument/codeAction
cpptools/didChangeFolderSettings
Code browsing service initialized
  Folder: /usr/local/include/ will be indexed
  Folder: /usr/include/ will be indexed
  Folder: /home/zhou/Desktop/test/ will be indexed
  Folder: /usr/include/linux/ will be indexed
textDocument/didOpen
Discovering files...
textDocument/documentSymbol
  Processing folder (recursive): /usr/local/include/
  Processing folder (recursive): /usr/include/
sending compilation args for /home/zhou/Desktop/test/Untitled-1.c
  include: /usr/include/linux
  include: /usr/include/c++/8.2.1
  include: /usr/include/c++/8.2.1/x86_64-pc-linux-gnu
  include: /usr/local/include
  include: /usr/include
  other: --gcc
  other: --gnu_version=80100
  stdver: --c11
  intelliSenseMode: gcc
Checking for syntax errors: file:///home/zhou/Desktop/test/Untitled-1.c
queue_update_intellisense for files in tu of: /home/zhou/Desktop/test/Untitled-1.c
terminating child process: 6960
errorSquiggles count: 2
Tag Parser will be used for IntelliSense operations in: file:///home/zhou/Desktop/test/Untitled-1.c
textDocument/codeAction
1 include path suggestion(s) discovered.
cpptools/activeDocumentChange
cpptools/textEditorSelectionChange
  Processing folder (recursive): /home/zhou/Desktop/test/
  Processing folder (recursive): /usr/include/linux/
  Discovering files: 16410 file(s) processed
  0 file(s) removed from database
Done discovering files.
Populate include completion cache.
Parsing remaining files...
  tag parsing file: /usr/include/OpenImageIO/pugixml.cpp
  Parsing: 1 files(s) processed
Done parsing remaining files.
Database safe to open
cpptools/activeDocumentChange
cpptools/textEditorSelectionChange
cpptools/activeDocumentChange
cpptools/textEditorSelectionChange

After adding and re-opening the folder:

workspace/didChangeConfiguration
IntelliSense Engine = Default.
The extension will use the Tag Parser for IntelliSense when #includes don't resolve.
Autocomplete is enabled.
Error squiggles are enabled.
File exclude: **/.git
File exclude: **/.svn
File exclude: **/.hg
File exclude: **/CVS
File exclude: **/.DS_Store
File exclude: **/.vscode
Search exclude: **/node_modules
Search exclude: **/bower_components
Search exclude: **/.vscode
textDocument/didOpen
cpptools/queryCompilerDefaults
Attempting to get defaults from compiler found on the machine: '/usr/bin/gcc'
terminating child process: 7325
terminating child process: 7327
terminating child process: 7330
terminating child process: 7333
terminating child process: 7335
terminating child process: 7338
terminating child process: 7340
terminating child process: 7342
terminating child process: 7344
cpptools/activeDocumentChange
cpptools/textEditorSelectionChange
textDocument/documentSymbol
textDocument/codeAction
cpptools/didChangeFolderSettings
Code browsing service initialized
  Folder: /usr/local/include/ will be indexed
  Folder: /usr/include/ will be indexed
  Folder: /home/zhou/Desktop/test/ will be indexed
  Folder: /usr/include/linux/ will be indexed
textDocument/didOpen
Discovering files...
textDocument/documentSymbol
  Processing folder (recursive): /usr/local/include/
  Processing folder (recursive): /usr/include/
sending compilation args for /home/zhou/Desktop/test/Untitled-1.c
  include: /usr/include/linux
  include: /usr/include/c++/8.2.1/tr1
  include: /usr/include/c++/8.2.1
  include: /usr/include/c++/8.2.1/x86_64-pc-linux-gnu
  include: /usr/local/include
  include: /usr/include
  other: --gcc
  other: --gnu_version=80100
  stdver: --c11
  intelliSenseMode: gcc
Checking for syntax errors: file:///home/zhou/Desktop/test/Untitled-1.c
queue_update_intellisense for files in tu of: /home/zhou/Desktop/test/Untitled-1.c
terminating child process: 7356
errorSquiggles count: 1
textDocument/codeAction
  Processing folder (recursive): /home/zhou/Desktop/test/
  Processing folder (recursive): /usr/include/linux/
  Discovering files: 16411 file(s) processed
  0 file(s) removed from database
Done discovering files.
Populate include completion cache.
Parsing remaining files...
  Parsing: 0 files(s) processed
Done parsing remaining files.

The reason I thought maybe the compilerPath was not set was because I didn't see any define: lines in the log after the include: lines. Did you manually remove them or are they really not there? It could be a problem with the compiler querying. I know I haven't tested 8.2.1 yet.

@bobbrow but "compilerPath": "/usr/bin/gcc" was set by default and I haven't touched it

have you tried #include <unistd.h> ?

EDIT:
"unistd.h is the C/C++ header file that is your code's entry point to various constant, type and function declarations that comprise the POSIX operating system API. #include gets you, among other things: the infamous NULL pointer definition..." Adrian Ho (from Quora)

Closing this issue due to long inactivity. If you update to the latest version of the C/C++ extension and your issue still persists, please re-open the issue and reply with additional information that can help us investigate the issue.

Met the same issue

have you tried #include <unistd.h> ?

EDIT:
"unistd.h is the C/C++ header file that is your code's entry point to various constant, type and function declarations that comprise the POSIX operating system API. #include gets you, among other things: the infamous NULL pointer definition..." Adrian Ho (from Quora)

solved my issue

Was this page helpful?
0 / 5 - 0 ratings