Issue Type: Bug
1) Create two .c files and one .h file
2) .h file should have an extern declaration.
3) One .c file should have the definition of the above declared function.
4) Other .c file should having the code to call the function.
5) From the code which is calling the function, use the goto definition and it will take you to the extern declaration.
Extension version: 0.21.0
VS Code version: Code 1.31.0 (7c66f58312b48ed8ca4e387ebd9ffe9605332caa, 2019-02-05T22:32:14.164Z)
OS version: Darwin x64 18.2.0
System Info
|Item|Value|
|---|---|
|CPUs|Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz (12 x 2200)|
|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: enabled
rasterization: enabled
surface_synchronization: enabled_on
video_decode: enabled
webgl: enabled
webgl2: enabled|
|Load (avg)|1, 2, 2|
|Memory (System)|16.00GB (0.17GB free)|
|Process Argv||
|Screen Reader|no|
|VM|0%|
I'm not able to reproduce the bug. The code that is calling the function has a #include to the header file, right? Does this repro with a "extern int test();" method or does the signature of the function need have certain requirements?
extern void print_test(void); //goto definition from main.c will take us here
void print_test() //ideally goto definition from main.c should take us here
{
printf("Testing...\n");
}
int main()
{
printf("Testing VSCode\n");
print_test(); //execute goto definition here
return 0;
}
Yeah, I'm still not reproing the bug -- Go To Def is going to the definition in func_defs.c.
Does your c_cpp_properties.json settings have anything unsual set? Do you see any error squiggles? Do you see any error messages when you enable logging.
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
Failed to create IntelliSense client. Can't create intellisense client for /xxxx/func_declaration.h
Failed to create IntelliSense client. Can't create intellisense client for /xxxx/main.c
textDocument/hover
cpptools/activeDocumentChange
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
textDocument/codeAction
textDocument/definition
textDocument/didClose
textDocument/codeAction
cpptools/activeDocumentChange
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
textDocument/didOpen
Checking for syntax errors: file:///xxxxx/func_declaration.h
queue_update_intellisense for files in tu of: /xxxxxx/main.c
textDocument/codeAction
errorSquiggles count: 0
errorSquiggles count: 0
Do these files all exist under the workspace folder?
The "failed to create IntelliSense client" error is bad -- does that still repro (it's not in your 2nd debug log).
If you switch the C_Cpp.intelliSenseEngine setting to "Tag Parser" does Go to Definition work?
Setting "C_Cpp.intelliSenseEngine" to "Tag Parser" worked.
All the files are under the same workspace. Is this the solution? Shall we close this issue?
To understand this issue we should go back to reading C language specification. So lets dive in.
First, you define a function in func_defs.c file.
void print_test() {
printf("Testing...\n");
}
Then, you declare it in func_declaration.h file:
extern void print_test(void);
Now, lets check what we have. We have "void print_test()" function definition and "void print_test(void)" declaration. Wait... Something is not right... print_test() and print_test(void) are equal? Ok, now lets check what ISO 9899 standard says (read: C99 standard). It states under paragraph ‘6.7.5.3 Function declarators (including prototypes)’ that:
10 — The special case of an unnamed parameter of type void as the only item in the list
specifies that the function has no parameters.
14 — An identifier list declares only the identifiers of the parameters of the function. An empty
list in a function declarator that is part of a definition of that function specifies that the function has no parameters. The empty list in a function declarator that is not part of a definition of that function specifies that no information about the number or types of the parameters is supplied.
So now we now that function defined/declared with void says that function takes no arguments and functions, that are defined/declared with empty parameter list, has not specified parameter list and that you can pass undefined number to this function, which is highly not recommended and compilers will give you warnings. So you should always specify function parameters including functions, that do not receive any parameters.
In C++ there is no difference between these functions. So do not mistake C for C++ because they are not the same languages.
I think that intellisense should give a warning in these cases, but should make a jump to definition of the function because in C there can by only one function with "this" name.
@Aukstkalnis I believe this issue has already been fixed with https://github.com/microsoft/vscode-cpptools/issues/3609 -- it should be available next week with our Insiders release. If it's not fixed in that release or if you believe it's a different bug, could you provide a simple test case that repros a bug so we can check if it's fixed with our internal builds?
Closing because we believe this was fixed (by https://github.com/microsoft/vscode-cpptools/issues/3609 ). If you are still seeing the issue, please let us know.