27 Oct, 2007, Guest wrote in the 1st comment:
Votes: 0
If you happen to be compiling the latest copy of the Diku IMC2 client, you might run into the following:

Quote
Compiling o/imc.o….
cc1: warnings being treated as errors
imc.c: In function 'imclog':
imc.c:218: warning: passing argument 2 of 'vsnprintf' with different width due to prototype
imc.c:221: warning: passing argument 2 of 'snprintf' with different width due to prototype
imc.c: In function 'imcbug':
imc.c:238: warning: passing argument 2 of 'vsnprintf' with different width due to prototype
imc.c:241: warning: passing argument 2 of 'snprintf' with different width due to prototype


The warnings will run on throughout the file. I'm not sure what the cause is but the workaround for the moment appears to be to remove -Wconversion from your Makefile. When I did that, the warnings went away.

In case it helps anyone, the functions producing the above warnings - I'd like to figure out a proper fix:

/* Generic log function which will route the log messages to the appropriate system logging function */
void imclog( const char *format, … )
{
char buf[LGST], buf2[LGST];
char *strtime;
va_list ap;

va_start( ap, format );
vsnprintf( buf, LGST, format, ap );
va_end( ap );

snprintf( buf2, LGST, "IMC: %s", buf );

strtime = ctime( &imc_time );
strtime[strlen( strtime ) - 1] = '\0';
fprintf( stderr, "%s :: %s\n", strtime, buf2 );

return;
}

/* Generic bug logging function which will route the message to the appropriate function that handles bug logs */
void imcbug( const char *format, … )
{
char buf[LGST], buf2[LGST];
char *strtime;
va_list ap;

va_start( ap, format );
vsnprintf( buf, LGST, format, ap );
va_end( ap );

snprintf( buf2, LGST, "***BUG*** IMC: %s", buf );

strtime = ctime( &imc_time );
strtime[strlen( strtime ) - 1] = '\0';
fprintf( stderr, "%s :: %s\n", strtime, buf2 );

return;
}
27 Oct, 2007, Dorian wrote in the 2nd comment:
Votes: 0
It is just telling you that the type of the integer you are passing as the second argument is of a bigger type than that parameter in the function supports. A cast should deal with it easily.
27 Oct, 2007, Guest wrote in the 3rd comment:
Votes: 0
Then I guess that begs the question. What type is assigned when it's done like so:

#define LGST 4096

The prototype for vsnprintf calls for a size_t in the second argument.
27 Oct, 2007, Tyche wrote in the 4th comment:
Votes: 0
Now if everyone would have followed Tyche's big book of C++ programming standards they'd not be in this pickle…
http://sourcery.dyndns.org/wiki.cgi?CppC...

See the heading Literals. This particular idea applies to C as well.

;-)
27 Oct, 2007, kiasyn wrote in the 5th comment:
Votes: 0
*bookmarks link*
28 Oct, 2007, Guest wrote in the 6th comment:
Votes: 0
An interesting read there Tyche. I'll have to keep that one handy.

However, for the purposes of C code, using a const int in place of a #define didn't work. At the core of the problem is this:
#define LGST 4096
#define SMST 1024


Changing those to:
const int LGST = 4096;
const int SMST = 1024;


resulted in several new errors such as:
Quote
imc.c: In function 'imc_find_social':
imc.c:7757: error: storage size of 'socname' isn't constant


The new errors are in addition to the existing warnings already being displayed, those did NOT go away as I was hoping they might. Switching to using g++ stops the problem, but the particular codebase I was testing with isn't in any kind of shape to switch permanently to that. It looks like -Wconversion isn't really well suited to use with straight C in the newer GCC compilers.
29 Oct, 2007, David Haley wrote in the 7th comment:
Votes: 0
If it wants a size_t, declare it as a size_t. Or, if you really need it to be a #define, make it #define LGST ((size_t) 4096).
29 Oct, 2007, Guest wrote in the 8th comment:
Votes: 0
Hmm. I must have spaced. I'll have to see if declaring it a size_t makes any difference.
29 Oct, 2007, David Haley wrote in the 9th comment:
Votes: 0
Well, you might have to keep it a define, because gcc might not allow any form of variables as an array size, even if the variable is const. (g++ fixes that, IIRC.)

And nice handle title, incidentally. :wink:
29 Oct, 2007, Guest wrote in the 10th comment:
Votes: 0
Changing the definition to a size_t had no impact. It still complained, which makes even less sense now. But you're right, with g++ it doesn't complain since I've got AFKMud setup to use dozens of const int declarations that used to be #define statements.

And I though the handle was appropriate too since certain people here seem to think I don't have a sense of humor, I figured why not indicate it :)
29 Oct, 2007, David Haley wrote in the 11th comment:
Votes: 0
Does it complain if you make it a define with a cast in the define? (e.g., #define FOO ((size_t) 1234) )
29 Oct, 2007, Guest wrote in the 12th comment:
Votes: 0
Yes. It complains regardless of what's been done, as long as the -Wconversion flag remains in the Makefile. It leaves me to assume that the flag is only meant for use in c++ code since it doesn't complain if I compile in g++.
0.0/12