From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
Subject: Re: bookkeeping to prepare for a 64-bit EMACS_INT on 32-bit hosts
Date: Mon, 02 May 2011 15:12:09 -0300 [thread overview]
Message-ID: <jwvipttc6zz.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <4DBED72D.9070207@cs.ucla.edu> (Paul Eggert's message of "Mon, 02 May 2011 09:09:17 -0700")
>>>>> >>> > - /* The EMACS_INT cast avoids a warning. */
>>>>> >>> > + EMACS_INTPTR ii = i;
>>>>> >>> > + gpointer gi = (gpointer) ii;
>>>> >> Is there a particular reason why you use an intermediate var rather
>>>> >> than use the more concise "(gpointer) (EMACS_INTPTR) i"?
>>> > To avoid a cast.
>> I'm not sure what is the formal definition of "cast" in C, but at least
>> from my point of view, your code performs just the same kind of coercion
>> as a cast.
> The runtime behavior is the same, but avoiding the cast can catch more
> errors. Suppose "i" is of type "struct tm *", say, and the programmer
> made a mistake. Then GCC will issue a helpful diagnostic for the form
> with just one cast, but it won't diagnose the more-concise form with
> two casts.
Right, implicit coercions are indeed checked more thoroughly since the
programmer doesn't say explicitly to shut up.
My favorite choice would be to force all casts to have a more easily to
find shape (e.g. so `grep' can find them) and to split them into various
categories, so the above EMACS_INTPTR cast would be labeled as
"checked" or "safe", so the compiler can output warnings.
>>> > If you prefer conciseness to avoiding these casts, I can easily change
>>> > these to the more-concise form.
>> I do prefer the more concise form, and paradoxically part of the reason
>> is because it is uses a explicit coercion rather than an implicit one.
> OK, will do (unless the above argument convinced you :-).
Given that
#define checked_cast(t,x) ({ t v = (x); v})
can't be written in ISO C (AFAIK), I either form will be suboptimal,
so there's no need to change the code.
Stefan
next prev parent reply other threads:[~2011-05-02 18:12 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-29 8:08 bookkeeping to prepare for a 64-bit EMACS_INT on 32-bit hosts Paul Eggert
2011-04-29 8:49 ` Eli Zaretskii
2011-04-29 9:06 ` Paul Eggert
2011-04-29 9:17 ` Eli Zaretskii
2011-04-29 16:04 ` Stefan Monnier
2011-04-29 17:10 ` Eli Zaretskii
2011-04-29 17:32 ` Lars Magne Ingebrigtsen
2011-04-29 17:45 ` Paul Eggert
2011-04-29 18:50 ` David De La Harpe Golden
2011-04-30 5:00 ` Stephen J. Turnbull
2011-04-30 1:37 ` Paul Eggert
2011-05-02 14:46 ` Stefan Monnier
2011-05-02 16:09 ` Paul Eggert
2011-05-02 18:12 ` Stefan Monnier [this message]
2011-05-02 19:23 ` Paul Eggert
2011-05-02 19:49 ` Stefan Monnier
2011-04-30 6:54 ` Paul Eggert
2011-04-30 7:30 ` Eli Zaretskii
2011-04-29 8:56 ` support " Paul Eggert
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvipttc6zz.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=eggert@cs.ucla.edu \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.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.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).