Re: (trivia) remove useless typecast around `jif' variable



Jan Engelhardt wrote:
On Mar 5 2007 19:12, Michael Tokarev wrote:

Date: Mon, 5 Mar 2007 19:12:51 +0300 (MSK)
From: Michael Tokarev <mjt@xxxxxxxxxx>
To: undisclosed-recipients: ;

I have no clue what you sent it to, so I added linux-kernel again.

Oops.. I forgot to add the To: header (it was only sent to lkml).
][
In case we wanted to use different types, we would also have to
change the accompanying %lu into %llu. Only changing jif to u64 will
cause a problem, as the compiler does _not_ automatically
promote/demote types in varargs that already have a certain size. In
other words,

Sure thing, the change will be needed. But the thing is - with the
cast in place, compiler will be completely silent, while w/o the cast
it will produce a warning (or at least it's able to).

Generally, casts are bad, that's the point. Especially redundrand
ones like here.

As a side note, I dislike when people remove casts from functions
returning void*. For example,

struct somestruct *foo;

foo = (struct somestruct *)kmalloc(sizeof(struct somestruct));

With the cast in place, the compiler will warn if somestruct will
be changed to something else, but without the cast, the compiler
will happily accept the (now wrong) line.

[]
will throw a warning (rightfully if you ask me).

Yes, that's what i was referring to when said "let the compiler
do some work for us".

/mjt
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • Re: a case for multiple inheritance
    ... and overrides the write functions to change ... the compiler would optimize it so that the double function call would be ... private new void Foo ... The cast not much ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: problem with memcpy and pointers/arrays confusion - again
    ... this second method is known as an explicit conversion, or cast. ... The cast, in effect, tells the compiler: ... the malloc function. ... function taking a size_t as a parameter and returning a void pointer (i.e. ...
    (comp.lang.c)
  • Re: about the array
    ... 3- If you cast to the wrong type by accident, ... are malloc and free. ... the compiler should issue a diagnostic - gcc ... unknown set of arguments, and return an int. ...
    (comp.lang.c)
  • Re: Can generics really produce strongly typed collections?
    ... The compiler won't detect the bug at compile time. ... will try to cast to B, ... The "foreach" statement specifically behaves in the way you ... interface, assuming one exists. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: a case for multiple inheritance
    ... and overrides the write functions to change ... the compiler would optimize it so that the double function call would be ... private new void Foo ... The cast not much ...
    (microsoft.public.dotnet.languages.csharp)