Error "a label can only being part of a statement and a declaration being not a statement" workaround

Source: Internet
Author: User
Tags goto

A goto statement was used before the code was written, and the result was compiled to hint that a label can only being part a statement and a declaration was not a statement was not understood at first because it had never been encountered before Of the mistake, Google can not find a satisfactory answer, and finally carefully pondered the error, and contrast code, finally found the crux of the problem: it is due to me in the label after the declaration of variables caused by the error, label can only be a part of the statement, The declaration of a variable is not a statement.

The rough flow of the original code is as follows:

if (!zmhss_fsready ()) {
Goto Defaul_init;
}

........

Defaul_init:

struct Rlimit rlmt;

if (Ccf->rlimit_nofile!=-1) {
Rlmt.rlim_cur = (rlim_t) ccf->rlimit_nofile;
Rlmt.rlim_max = (rlim_t) ccf->rlimit_nofile;

if (Setrlimit (rlimit_nofile, &RLMT) = = 1) {

Exit (2);
}
}

It is the above sentence struct rlimit RLMT, which eventually led to the error of the compilation process, the solution is to struct rlimit rlmt, and to move the declaration of the variable to the label before the modified code structure is as follows:

struct Rlimit rlmt;

if (!zmhss_fsready ()) {
Goto Defaul_init;
}

........

Defaul_init:

if (Ccf->rlimit_nofile!=-1) {
Rlmt.rlim_cur = (rlim_t) ccf->rlimit_nofile;
Rlmt.rlim_max = (rlim_t) ccf->rlimit_nofile;

if (Setrlimit (rlimit_nofile, &RLMT) = = 1) {

Exit (2);
}
}

After the above changes, the problem can be solved. An extension of this problem is that when writing code, the declaration of a variable should not appear after the label, such as the case structure in a switch statement may encounter similar problems.

PS: From a #if #endif宏块goto到宏块以外, there will be a compile alert.

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.