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.