C language, VC compiler cl, how to support variables do not have to declare at function start

Source: Internet
Author: User

Windows, with the VC compiler cl.exe, compiled nginx third-party module, there is a similar code error:

Static ngx_int_t
Ngx_http_zip_main_request_header_filter (ngx_http_request_t *r)
{
ngx_http_variable_value_t *VV;
ngx_http_zip_ctx_t *ctx;

if (CTX = Ngx_http_get_module_ctx (R, ngx_http_zip_module))! = NULL)
return Ngx_http_next_header_filter (R);

if (vv = Ngx_palloc (R->pool, sizeof (ngx_http_variable_value_t)) = = = NULL)
return ngx_error;

/* Look for X-archive-files */
ngx_int_t variable_header_status = NGX_OK;

Error out in ngx_int_t variable_header_status = NGX_OK;:

MOD_ZIP/NGX_HTTP_ZIP_MODULE.C (195): Error C2275: ' ngx_int_t ': illegal use of t
His type as an expression

Check it out, because C's compiler requires that the variable's reputation be placed on the head of a function block, and C + + has no such requirement. Put three of the famous variables at the beginning of a function.

The same code can be compiled and passed under GCC.

VC has no what compile option can support advanced point of C. The VC compiler I'm using is already the one that vs2012 comes with.


There is no way.
Because VC even to the latest 2013 also support the C89 standard, because it is essentially a C + + compiler, and you need the syntax is C99 standard after the support, so GCC can be compiled through.

There are two ways to solve this problem:
One is to change the code to conform to the C89 standard.
Second, compile with MinGW

Add in the Compile command

-c99

Visual Studio 2012 does not support C99, but Visual Studio 2013 supports it.

C language, VC compiler cl, how to support variables do not have to declare at function start

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.