All of lore.kernel.org
 help / color / mirror / Atom feed
From: J William Piggott <elseifthen@gmx.com>
To: Sami Kerola <kerolasa@iki.fi>
Cc: util-linux@vger.kernel.org, Karel Zak <kzak@redhat.com>
Subject: Re: pull: hwclock 27 changes
Date: Thu, 26 Jan 2017 21:07:50 -0500	[thread overview]
Message-ID: <5feac9a5-e3e3-5148-60a0-fb3197a1caa8@gmx.com> (raw)
In-Reply-To: <alpine.LNX.2.20.1701252136160.492@imuri>



On 01/25/2017 04:54 PM, Sami Kerola wrote:
> On Sun, 22 Jan 2017, J William Piggott wrote:
>> On 01/14/2017 05:51 PM, J William Piggott wrote:
>>> On 01/14/2017 04:34 AM, Sami Kerola wrote:
>>>> Preferably there should not be casts at all. But sometimes they are hard 
>>>> to avoid, and then one should do as few casts as possible to avoid cutting 
>>>> bits out.
>>>>
>>>> Think casting in terms of shape sorting toy. The more data is casted 
>>>> through none-matching types the more the original shape is modified to fit 
>>>> to storage where it is pushed.
>>>>
>>>> That is also the reason why casting to time_t in this case makes sense. 
>>>> While it might be that right now, on systems we happen to use, int and 
>>>> time_t are the same type there are no guarantees about other systems and 
>>>> future. In practical terms; casting exactly to matching storage type is 
>>>> the right way to avoid damaging data.
>>>
>>> What I'm trying to say is, assignment operators automatically convert
>>> the right operand to the type of the left operand; making your cast
>>> unnecessary. Try it, build hwclock with the cast. Now, remove the cast
>>> and build it. The resulting binaries are bit for bit identical.
>>>
>>> ISO C11:
>>> The type of an assignment expression is the type the left operand would have
>>> after lvalue conversion.
>>>
>>> In simple assignment (=), the value of the right operand is converted to
>>> the type of the assignment expression and replaces the value stored in
>>> the object designated by the left operand.
>>
>> It wasn't the intent of my previous message to be offensive in any way,
>> Sami. I was only trying to state my position using different language,
>> so as not to simply repeat myself.
>>
>> Also, I'm not continuing this topic to be argumentative. The reason is
>> for my own education. If my opinion is wrong, that is fine; I would like
>> to understand why, so as to improve my own coding.
>>
>> As I further read the ISO C standard, I'm more convinced of my belief.
>> It seems to me the compiler is required to use the type conversion
>> routine associated with assignment operators, because it must yield two
>> different results. A /qualified/ left operand type is stored, but the
>> evaluation of the assignment expression returns an /unqualified/ left
>> operand type. Since using the assignment operator's type conversion
>> routine is required (if I'm correct), the compiler would ignore any cast
>> on the results of the right hand operand for code optimization, yes?
>>
>> That seems to be true for my compiler, as the cast makes no difference
>> in the resulting binary.
>>
>> If anyone knows the correct answer to this, I am very interested in
>> learning it. Thank you in advance.
> 
> Hi William,
> 
> Sorry for late reply, I took a bit time off from reading / replying 
> emails.

No worries Sami. I thought you might have been angry at something I
wrote; it seem to unintentionally happen sometimes when talking across
cultural borders.

> 
> Correct the cast that is in place now is technically unnecessary. Value of 
> that cast is to remind return value type and storage type differ. Such 
> assignments can, at least in theory, cause bugs so being explicit about 
> them is a good thing. As a matter of fact anything that makes code easier 
> to understand is welcome.
> 
> That said now I doubt whether 'technically unnecessary' cast is really a 
> thing that clarifies, but confuses code reader. Comments would be nice, 
> meanwhile I will think about this.
> 

I understood the previous symbolism of the cast; to draw attention to
dropping the fractional part of a variable. I don't perceive any value
in using it on the floor(3) function.

  reply	other threads:[~2017-01-27  2:07 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-31 21:41 pull: hwclock 27 changes Sami Kerola
2017-01-03 14:34 ` J William Piggott
     [not found] ` <05e4405f-8096-9261-f9f2-d2c6b84675bc@gmx.com>
2017-01-07 19:37   ` J William Piggott
2017-01-07 20:32     ` J William Piggott
2017-01-07 23:06     ` Sami Kerola
2017-01-08  9:39       ` Sami Kerola
2017-01-08 21:21         ` J William Piggott
2017-01-08 10:09       ` Sami Kerola
2017-01-08 21:21         ` J William Piggott
2017-01-08 21:21       ` J William Piggott
2017-01-11 21:44         ` Sami Kerola
2017-01-13  1:30           ` J William Piggott
2017-01-14  9:34             ` Sami Kerola
2017-01-14 22:51               ` J William Piggott
2017-01-22 19:03                 ` J William Piggott
2017-01-25 21:54                   ` Sami Kerola
2017-01-27  2:07                     ` J William Piggott [this message]
2017-02-02 15:04                       ` [ping] Karel: " J William Piggott
2017-02-03 22:41                         ` Sami Kerola
2017-02-11 17:10                           ` J William Piggott
2017-02-04 18:47                         ` Karel Zak
2017-02-05 22:37                           ` Sami Kerola
2017-02-09 10:43                         ` Karel Zak
2017-02-09 11:09                         ` Karel Zak
2017-02-11 17:10                           ` J William Piggott
2017-01-09 11:32       ` Karel Zak
2017-01-09 13:53         ` J William Piggott
2017-01-09 20:48           ` Bjarni Ingi Gislason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5feac9a5-e3e3-5148-60a0-fb3197a1caa8@gmx.com \
    --to=elseifthen@gmx.com \
    --cc=kerolasa@iki.fi \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.