Re: [PATCH v4 1/6] drm/format-helper: Add drm_fb_xrgb8888_to_gray8_line()

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

 



Hi

Am 14.02.22 um 13:47 schrieb Ville Syrjälä:
On Mon, Feb 14, 2022 at 01:12:48PM +0100, Thomas Zimmermann wrote:
Hi

Am 14.02.22 um 11:38 schrieb Andy Shevchenko:
On Mon, Feb 14, 2022 at 10:03:53AM +0100, Thomas Zimmermann wrote:
Am 11.02.22 um 16:41 schrieb Andy Shevchenko:

...

IMO *always* prefer a for loop over while or do-while.

The for (i = 0; i < N; i++) is such a strong paradigm in C. You
instantly know how many times you're going to loop, at a glance. Not so
with with the alternatives, which should be used sparingly.

while () {}  _is_ a paradigm, for-loop is syntax sugar on top of it.

Naw, that's not true.

In the section 3.5 "Loops - While and For" in "The C Programming
Language" 2nd by K&R, the authors said:

Year of publication: 1988 . It's not the most up-to-date reference for C
programming.


	The for statement ... is equivalent to ... while..."

They said that for is equivalent to while, and not otherwise.

Even leaving readability aside, it's not equivalent. You can declare
variables as part of the for statement. (I know it's not the kernel's
style.) Also, 'continue' statements are not well-suited in for loops,
because it's non-obvious if the loop's update statement is being
executed. (It isn't.)

It is.

'continue' is just shorthand for 'goto end_of_loop_body'.

Well, indeed. lol

Fun fact: I actually had to look this up and still got it wrong. Let me just count it under proving-my-point: continue in a for statement is a bad idea and for isn't equivalent to while.

Best regards
Thomas



--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux