?
=?ISO-8859-1?Q?Martin_J=F8rgensen?=
Richard said:Martin Jørgensen said:
Hi, there... I almost eliminated all errors/warnings. Only got a few left.
1. The line: "sscanf(line, "%s", &argument);" gives:
warning: format %s expects type char * , but argument 3 has type
char (*)[63u]
Definitions: "char line[64], argument[10];"
Is it afraid that sscanf will put more than 10 characters into argument?
What's the solution?
if(sscanf(line, "%9s", argument) == 1)
{
Your spurious & on &argument means you're passing char (*)[10] - a pointer
to an array of 10 char - instead of char *, which is what you get when you
pass the name of an array of char to a function.
Thanks a lot... Actually I forgot... I had #defined something called
maxsize or something. Suppose I had "#define maxsize 10", could I then
write if(sscanf(line, "%(maxsize-1)s", argument) == 1) ? That would be
better...
Drop the const from fp. The fseek function needs to be able to modify the
file position indicator member of the object pointed to by fp.
Much better.
3. I have a file called array_functions.c which has:
void int_fillinnumbers(int fillvalue, int startx,
int stopx, int starty,
int stopy, int **array)
{
int i, j; /* local index variables */
for(j=starty; j<=stopy; j++)
{
for(i=startx; i<=stopx; i++)
array[j] = fillvalue; /* integer-fill */
}
}
This function is used different places in the program and is called from
main.c. The problem is:
warning: no previous prototype for int_fillinnumbers
What's it whining about? It don't need another prototype, IMO...
If the function is called only from within the translation unit in which it
is defined, and is called only /after/ the function definition, then you
can ignore the warning. Otherwise, but this:
void int_fillinnumbers(int fillvalue, int startx,
int stopx, int starty,
int stopy, int **array);
Damn... I also had that............... I thought....
I just accidentally deleted the semi-colon and thought it was still
there, therefore I didn't understand it before...
in a header, and #include that header in all translation units that contain
calls to the function. It is also wise to #include it in the translation
unit where the function is defined, as this will catch any mods that are
done to the definition which have not been reflected in the header.
#pragmas are, by definition, non-portable (with one trivial C99 exception
which I'll ignore as irrelevant on this occasion).
The fix here is: don't use nasty/stupid unsigned/signed-tricks!
But I don't think I can't avoid it, as I'm using some old code which I
don't know how to rewrite... The messages are: "warning: comparison
between signed and unsigned", and I tried to debug this sh*t, but it's
really nasty so I didn't understood it. For instance it decremented an
unsigned variable below 0, so I dare not even cast any of it to the same
type if it makes any problems...
But hey, let me hear - perhaps I can explicitly cast and get rid of the
warnings, without losing functionality: I have this:
for (i=1;i<=left;i++)
"i" is unsigned int, "left" is integer. Would it be absolutely safe to
rewrite the line to:
1. for (i=1;i<= (unsigned) left;i++)
or
2. for ((int) i=1;i<= left;i++)
And then get the same nasty bit-fiddling functionality and no warning?
I also have
if(l < mm) l++;
where "l" is unsigned long, "mm" is int...
And then I have an output-routine that prints a 2D-array of type double **:
void double_printout(int startcol, int stopcol,
int startrow, int stoprow,
double **array, char *indent,
unsigned digits)
{
int i, j; /* local index variables */
char formatstring[] = "-> %8.2f ";
printf("\n");
if(digits >=8 || digits <0)
{
printf("ERROR! Can't print that number of digits.\n");
quit_program(__FILE__, __LINE__);
}
formatstring[6] = (char)('0'+ digits);
for(j=startrow; j<=stoprow; j++)
{
printf("\n%2d: %s", j, indent);
for(i=startcol; i<=stopcol; i++)
printf( ("%s", formatstring), array[j]); /*<= WARNING!*/
}
printf("\n\n");
}
I know that's probably considered ugly coding but I wanted to pass an
unsigned "digits"-value, that determines how many decimal places after
the comma should be included in the output... Therefore I had to modify
the "formatstring", which is passed as an argument to printf().
The message is:
"warning: format not a string literal, argument types not checked"
I guess it's trying to tell me that "formatstring" is not a string
literal. But I don't know how to fix the problem, then and still get
this "number of digits passed into argument"-behaviour.
Last problem (I think / I hope - it looks much better now):
This is probably also a bit nasty, but I need the program to generate a
number of output-files that are consecutive numbered like
"file0000.vtk", "file0001.vtk", "file0002.vtk", "file0003.vtk",
"file0004.vtk", ......., "file0009.vtk", "file0010.vtk", "file0011.vtk",
....... "file0099.vtk", "file0100.vtk"....
Therefore I needed to figure out how many digits the "counter"-variable
took up. I found a good method I think... At least I couldn't find a
better method. I used:
/* calculate number of leading zero's for 3-digit numbers up to 999 */
counter = 2 - (int) log10( (double) *output_filestep );
Let's try it: output_filestep (is an int AFAIR) = 5. log(5) = 0.7. We
make it (cast it to become) an integer, so it becomes (int) 0.7 => 0.
Counter = 2, because then we need to fill in two zero, i.e. "file00" +
"5". My problem is:
"warning: cast from function call of type double to non-matching type
int"
I thought I already casted it to an integer with the (int) part and
therefore I thought I explicitly told the compiler not to complain about
this cast. How do I fix it/make the warning disappear?
And that's it... The compiling process would really look beautiful if I
could get rid of the last warnings, if you know what I mean
Best regards
Martin Jørgensen