error C2275 : illegal use of this type as an expression error C2275 : illegal use of this type as an expression c c

error C2275 : illegal use of this type as an expression


When you name your source files *.c, MSVC assumes it's compiling C, which means C89. All block-local variables need to be declared at the beginning of the block.

Workarounds include:

  • declaring/initializing all local variables at the beginning of a code block (directly after an opening brace {)
  • rename the source files to *.cpp or equivalent and compile as C++.
  • upgrading to VS 2013, which relaxes this restriction.


You might be using a version of C that doesn't allow variables to be declared in the middle of a block. C used to require that variables be declared at the top of a block, after the opening { and before executable statements.


Put braces around the code where the variable is used.

In your case that means:

if (ac > 1){    if (!parse_args(ac, av))    {        aff_error(ARGUMENTS);        return EXIT_FAILURE;    }}{    SERVICE_TABLE_ENTRY DispatchTable[] = {{MY_SERVICE_NAME, ServiceMain}, {NULL, NULL}};    StartServiceCtrlDispatcher(DispatchTable);}