title | description | ms.date | helpviewer_keywords | |||
---|---|---|---|---|---|---|
C Keywords | Keywords in Standard C and Microsoft C compiler extensions. | 12/8/2020 |
|
Keywords are words that have special meaning to the C compiler. In translation phases 7 and 8, an identifier can't have the same spelling and case as a C keyword. For more information, see translation phases in the Preprocessor Reference. For more information on identifiers, see Identifiers.
The C language uses the following keywords:
:::row::: :::column::: auto
break
case
char
const
continue
default
do
double
else
enum
:::column-end::: :::column::: extern
float
for
goto
if
inline
1, aint
long
register
restrict
1, areturn
:::column-end::: :::column::: short
signed
sizeof
static
struct
switch
typedef
typeof
typeof_unqual
union
unsigned
void
volatile
:::column-end::: :::column::: while
_Alignas
2, a_Alignof
2, a_Atomic
2, b_Bool
1, a_Complex
1, b_Generic
2, a_Imaginary
1, b_Noreturn
2, a_Static_assert
2, a_Thread_local
2, b :::column-end::: :::row-end:::
1 Keywords introduced in ISO C99.
2 Keywords introduced in ISO C11.
a Starting in Visual Studio 2019 version 16.8, these keywords are supported in code compiled as C when the /std:c11
or /std:c17
compiler options are specified.
b Starting in Visual Studio 2019 version 16.8, these keywords are recognized but not supported by the compiler in code compiled as C when the /std:c11
or /std:c17
compiler options are specified.
You can't redefine keywords. However, you can specify text to replace keywords before compilation by using C preprocessor directives.
The ANSI and ISO C standards allow identifiers with two leading underscores to be reserved for compiler implementations. The Microsoft convention is to precede Microsoft-specific keyword names with double underscores. These words can't be used as identifier names. For a description of the rules for naming identifiers, including the use of double underscores, see Identifiers.
The following keywords and special identifiers are recognized by the Microsoft C compiler:
:::row::: :::column::: __asm
5__based
3, 5__cdecl
5__declspec
5__except
5__fastcall
__finally
5 :::column-end::: :::column::: __inline
5__int16
5__int32
5__int64
5__int8
5__leave
5__restrict
:::column-end::: :::column::: __stdcall
5__try
5__typeof__
__typeof_unqual__
dllexport
4dllimport
4naked
4static_assert
6thread
4 :::column-end::: :::row-end:::
3 The __based
keyword has limited uses for 32-bit and 64-bit target compilations.
4 These are special identifiers when used with __declspec
; their use in other contexts is unrestricted.
5 For compatibility with previous versions, these keywords are available both with two leading underscores and a single leading underscore when Microsoft extensions are enabled.
6 If you don't include <assert.h>, the Microsoft Visual C compiler maps static_assert
to the C11 _Static_assert
keyword.
Microsoft extensions are enabled by default. To help create portable code, you can disable Microsoft extensions by specifying the /Za (Disable language extensions) option during compilation. When you use this option, some Microsoft-specific keywords are disabled.
When Microsoft extensions are enabled, you can use the keywords listed above in your programs. To conform to the language standard, most of these keywords have a leading double underscore. The four exceptions, dllexport
, dllimport
, naked
, and thread
, are used only with __declspec
and don't require a leading double underscore. For backward compatibility, single-underscore versions of the rest of the keywords are supported.