* (trivia) remove useless typecast around `jif' variable
@ 2007-03-05 16:12 Michael Tokarev
2007-03-05 16:29 ` Jan Engelhardt
[not found] ` <663650480-1173118082-cardhu_blackberry.rim.net-718749525-@bxe041-cell01.bisx.prod.on.blackberry>
0 siblings, 2 replies; 4+ messages in thread
From: Michael Tokarev @ 2007-03-05 16:12 UTC (permalink / raw)
in fs/proc/proc_misc.c:show_stat() routine (which handles /proc/stat
file), there's a local variable named 'jif' of type unsigned long,
declared as following:
static int show_stat(struct seq_file *p, void *v)
{
unsigned long jif;
But later on, it's explicitly casted to (unsigned long) in printf().
Remove the useless cast, to let the compiler to do the work for us
in case we'll want to use different type here (say, u64 or something).
Signed-Off-By: Michael Tokarev <mjt@tls.msk.ru>
--- linux-2.6.20/fs/proc/proc_misc.c.orig 2007-02-04 21:44:54.000000000 +0300
+++ linux-2.6.20/fs/proc/proc_misc.c 2007-03-05 19:06:09.000000000 +0300
@@ -521,15 +521,15 @@ static int show_stat(struct seq_file *p,
seq_printf(p,
"\nctxt %llu\n"
"btime %lu\n"
"processes %lu\n"
"procs_running %lu\n"
"procs_blocked %lu\n",
nr_context_switches(),
- (unsigned long)jif,
+ jif,
total_forks,
nr_running(),
nr_iowait());
return 0;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: (trivia) remove useless typecast around `jif' variable
2007-03-05 16:12 (trivia) remove useless typecast around `jif' variable Michael Tokarev
@ 2007-03-05 16:29 ` Jan Engelhardt
2007-03-05 20:18 ` Michael Tokarev
[not found] ` <663650480-1173118082-cardhu_blackberry.rim.net-718749525-@bxe041-cell01.bisx.prod.on.blackberry>
1 sibling, 1 reply; 4+ messages in thread
From: Jan Engelhardt @ 2007-03-05 16:29 UTC (permalink / raw)
To: Michael Tokarev; +Cc: Linux Kernel Mailing List
On Mar 5 2007 19:12, Michael Tokarev wrote:
>Date: Mon, 5 Mar 2007 19:12:51 +0300 (MSK)
>From: Michael Tokarev <mjt@tls.msk.ru>
>To: undisclosed-recipients: ;
I have no clue what you sent it to, so I added linux-kernel again.
>Subject: (trivia) remove useless typecast around `jif' variable
>
>in fs/proc/proc_misc.c:show_stat() routine (which handles /proc/stat
>file), there's a local variable named 'jif' of type unsigned long,
>declared as following:
>
>static int show_stat(struct seq_file *p, void *v)
>{
> unsigned long jif;
>
>But later on, it's explicitly casted to (unsigned long) in printf().
>Remove the useless cast, to let the compiler to do the work for us
>in case we'll want to use different type here (say, u64 or something).
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,
int foo(unsigned long x)
{
printk("%llu\n", x); /* and */
printk("%lu\n", x);
}
will throw a warning (rightfully if you ask me).
Jan
--
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: (trivia) remove useless typecast around `jif' variable
2007-03-05 16:29 ` Jan Engelhardt
@ 2007-03-05 20:18 ` Michael Tokarev
0 siblings, 0 replies; 4+ messages in thread
From: Michael Tokarev @ 2007-03-05 20:18 UTC (permalink / raw)
To: Jan Engelhardt; +Cc: Linux Kernel Mailing List
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@tls.msk.ru>
>> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: (trivia) remove useless typecast around `jif' variable
[not found] ` <663650480-1173118082-cardhu_blackberry.rim.net-718749525-@bxe041-cell01.bisx.prod.on.blackberry>
@ 2007-03-05 22:58 ` Michael Tokarev
0 siblings, 0 replies; 4+ messages in thread
From: Michael Tokarev @ 2007-03-05 22:58 UTC (permalink / raw)
To: Christopher.Prest; +Cc: linux-kernel
Christopher.Prest@rogers.com wrote:
> Yes sounds correct. How many other places are being casted as well?
Care to find them? :)
This one took my attention by a chance. I looked at various other files,
at least in fs/proc/, but don't see any other places like this.
/mjt
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-03-05 22:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-05 16:12 (trivia) remove useless typecast around `jif' variable Michael Tokarev
2007-03-05 16:29 ` Jan Engelhardt
2007-03-05 20:18 ` Michael Tokarev
[not found] ` <663650480-1173118082-cardhu_blackberry.rim.net-718749525-@bxe041-cell01.bisx.prod.on.blackberry>
2007-03-05 22:58 ` Michael Tokarev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox