I've installed vscode extension (ms-vscode.cpptools) from Microsoft to enable intellisense. But, when i typed MessageBox, the parameters have no labels.
It should be
MessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
My Question: Why MingW distribute the header files without labels?
It should be
MessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
That is not so.
The tooltip is showing you the declaration of the function, as declared
in MingGW's header winuser.h
. That declaration specifies the function's
prototype, consisting of:
as the tooltip does:
int MessageBoxW (HWND, LPCSTR, LPCSTR, UINT)
What you call "labels" are parameter-names. They are optional, and redundant,
in a function declaration, since the compiler does not need them to understand
how the declared function will be called, and what it returns. MessageBoxW
is to be called with arguments that are a HWND
, a LPCSTR
, another LPCSTR
,
and a UINT
, in that order; and it returns and int
.
The compiler requires parameters to be named in a function definition:
add.c
// definition
int add(int x, int y)
{
return x + y;
}
main.c
#include <stdio.h>
extern int add(int,int); // Declaration
int main()
{
printf("%d\n",add(3,4));
return 0;
}
Compile with maximum strictness, link and run:
$ gcc -Wall -Wextra -pedantic -o prog main.c add.c
$ ./prog
7
See also Function Declaration in C
Parameter-names are useful to human readers in a function-declaration when the declaration is accompanied by documentation of the function, since the documentation can then refer to the parameter-names to explain the function's behaviour:
/*
Return the sum of `x` and `y`
*/
int add(int x, int y);
But they are unnecessary to the compiler.
Like the MinGW windows headers, Micorosoft's own headers do not contain comments
to document the APIs, but they do contain parameter-names, and also SAL Annotations
of the parameter names. E.g. in Microsoft's WinUser.h
(SDK 2017) the declaration of MessageBoxW
is:
int
WINAPI
MessageBoxW(
_In_opt_ HWND hWnd,
_In_opt_ LPCWSTR lpText,
_In_opt_ LPCWSTR lpCaption,
_In_ UINT uType);
The SAL annotations, (_In_opt_
, _In_
and similar) are a non-standard Microsoft
language extension that supports static analysis of the correctness of code
implementing or invoking the APIs and they are used for that purpose by Microsoft's
compilers.
Such SAL-based static analysis needs names for the annotated parameters in order to provide meaningful diagnostics; hence the parameters have names in the annotated declarations in Microsoft's headers.
GCC, including MinGW ports, does not support SAL; so parameter names remain redundant in function declarations.