During the learning process operation testing the Linux exec function, a very simple piece of test code was written, as follows: 650) this.width=650; "Src=" http://s4.51cto.com/wyfs02/M02/88/5C/ Wkiol1fzyaybbmjbaaatd1678rc582.png "title=" screenshot from 2016-10-04 14:34:33.png "alt=" Wkiol1fzyaybbmjbaaatd1678rc582.png "/>
When compiling with GCC version 4.6.3 (Ubuntu/linaro 4.6.3-1ubuntu5), ask the question:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/88/5C/wKioL1fzYKyw6cBXAAAiGbnUgXM523.png "title=" Screenshot from 2016-10-04 15:56:06.png "alt=" Wkiol1fzykyw6cbxaaaigbnugxm523.png "/>
Later, compared to a reference book, and did not find the error (may not be the same as the GCC version), and later looked for additional information, found that the problem: for some parameters are variable-length array function, you must add a NULL value at the end of the parameter to indicate the end of the passed parameter. For example, the EXECL format ( A form of exec, which has a total of six expressions).
For functions with variable parameter arrays, some problems may arise. Take the form of execl as an example.
This function: execl (const char * path, const char * arg0, .../* (char*) 0 */);
When compiling with GCC, the following two types of problems may occur:
1 warning:not enough variable arguments to fit a sentinel (insufficient number of parameters);
workaround : The parameters can be filled. For the EXECL function above, a minimum of two parameters is required. (The path executable file name, which is the full path; arg, as a convention, indicates the destination file's paths as in path);
2 Warning:missing Sentinel in function call;
workaround : In the formal parameter list, add a null or take (char*) 0 can also, to the compiler (complier) Some hints: "Tell the compiler, do not look down, no parameters need to pass".
such as Execl ("/bin/date", "/bin/date", (char*) 0) with execl ("/bin/date", "/bin/date", NULL);
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/88/60/wKiom1fzZzfQsY4YAAA7UgdfzeU181.png "title=" Screenshot from 2016-10-04 16:23:12.png "alt=" Wkiom1fzzzfqsy4yaaa7ugdfzeu181.png "/>
In addition, for 0 and (char*) 0, in 64-bit operating systems, the integer 0 is 32 bits, and pointer 0 is 64 bits, but the compiler (complier) does not know, so the problem occurs.
This article is from the "slow Forward in pain" blog, please be sure to keep this source http://jjyynice.blog.51cto.com/10193818/1858709
For newbies, problems that may occur when some variadic functions are in use