[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] [PATCH] Cosmetic bugfix



Helmut Karlowski wrote:
Thanks. Why didn't you change the %ld into %d?

Well, %ld is used on other places, too and I assume authors had more than
32000 lines in mind ;)

I'll change it to %d!

This is a bad idea to use %d.

__LINE__ is an integer constant. That means that the preprocessor replace it by the text 40 or 40000 for example.

Now the rules of the C language. If an integer constant fits into an int, the constant has the "int" type, else it has the "long" type.

Then the rules with functions with a variable number of arguments, like printf(), or BIO_ALERT(), I guess. The arguments are pushed with their natural type on the stack, then can't be casted by any prototype.

This is particularly important when using -mshort.

If you do:
printf("%d", 40);
it works as expected since 40 is an int.

But if you do:
printf("%d", 40000);
it will fail because %d expects an int whereas 40000 is a long. If there a other arguments after that number, they will be shifted, too.

I have just tested that.

Miro Kropáček wrote:
+ BIO_ALERT (("block_IO []: %s, %ld: Specified cache size too small
(%li).", __FILE__, (long) __LINE__, size));

So I agree with MiKRO: casting integer constants such as __LINE__ is the only way to be sure of their type, and the "long" type should be enough in every case.

--
Vincent Rivière