Re: strtok_r has prototyped pointer of different width?
- From: Gil Hamilton <gil_hamilton@xxxxxxxxxxx>
- Date: Mon, 24 Mar 2008 16:32:56 +0100 (CET)
Johannes Bauer <dfnsonfsduifb@xxxxxx> wrote in
char x[123];
const char *delim = "abcd";
char *token;
char *saveptr;
strcpy(x, "foobar");
token = strtok_r(x, delim, &saveptr);
Which, compiled with
gcc -O2 -Wall -Wextra -Wformat-nonliteral -Wcast-align -Wpointer-arith
-Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes
-Wmissing-declarations -Winline -Wundef -Wnested-externs -Wcast-qual
-Wshadow -Wconversion -Wwrite-strings -o foo foo.c
Yields (among argc/argv unused) the following warning:
foo.c:13: warning: passing argument 2 of â??__strtok_r_1câ?? with
different width due to prototype
I've found no explanation - why is that?
The option -Wconversion is documented thus:
Warn if a prototype causes a type conversion that is different
from what would happen to the same argument in the absence of a
prototype.
If there were no function prototype, the single char argument to the
internal function __strtok_r_1c would be promoted to an int (generally 4
bytes, but depends on architecture) based on standard C language rules.
With the prototype, the char argument is not promoted. Hence, the width
of the argument passed changed as a result of the prototype, which is
what you asked for with -Wconversion.
Here is the same issue reduced to a minimal example -- compile with "gcc
-Wconversion -c foo.c":
extern void bar(char x);
void foo(void) { char y = 0; bar(y); }
Then comment out the "extern void ..." line and you'll see that the
warning goes away.
GH
.
- References:
- strtok_r has prototyped pointer of different width?
- From: Johannes Bauer
- strtok_r has prototyped pointer of different width?
- Prev by Date: strtok_r has prototyped pointer of different width?
- Next by Date: Re: Hi
- Previous by thread: strtok_r has prototyped pointer of different width?
- Next by thread: Socket connection return "Process file table overflow."
- Index(es):
Relevant Pages
|