unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Eli Zaretskii <eliz@gnu.org>
Cc: andrewjmoreton@gmail.com, emacs-devel@gnu.org
Subject: Re: Warnings in mingw64 builds on master
Date: Sun, 16 Aug 2020 21:21:36 -0700	[thread overview]
Message-ID: <c2404915-e179-9935-baf8-7af4cda76b91@cs.ucla.edu> (raw)
In-Reply-To: <835z9iiori.fsf@gnu.org>

On 8/16/20 8:39 AM, Eli Zaretskii wrote:
> the warning it emits has nothing to
> do with correctness of the code.

I'm not sure I follow. Although it's true that adding __attribute__ ((malloc)) 
does not turn formerly-incorrect code into correct code, the same thing is true 
of other function attributes like _Noreturn. But that doesn't mean we shouldn't 
use function attributes.

The main reason I like __attribute__ ((malloc)) has little to do with improving 
performance (is that what you meant by "improving the code"?); it has to do with 
understanding the code and using that understanding to avoid and/or fix bugs. 
When I see code like this:

    char *p = xmalloc (s);
    memcpy (p, q, r);

I mentally have to answer questions like "is r <= s?" because otherwise the 
behavior is undefined. But I do not have to mentally answer questions like "are 
*p and *q aliases?" - even though the behavior of memcpy would be undefined if 
they were aliases - because malloc has __attribute__ ((malloc)) and this means 
*p cannot alias with anything else.

This is not simply a matter of memcpy vs memmove. In C one must constantly worry 
about aliasing. These worries are lessened with __attribute__ ((malloc)), so the 
attribute is typically a win.




  reply	other threads:[~2020-08-17  4:21 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-14 22:37 Warnings in mingw64 builds on master Andy Moreton
2020-08-15 16:24 ` Eli Zaretskii
2020-08-15 18:48   ` Andy Moreton
2020-08-15 19:03     ` Eli Zaretskii
2020-08-15 19:39       ` Andy Moreton
2020-08-15 20:36       ` Óscar Fuentes
2020-08-16  2:31         ` Eli Zaretskii
2020-08-16 11:21           ` Andy Moreton
2020-08-16 14:44             ` Eli Zaretskii
2020-08-16 16:45               ` Óscar Fuentes
2020-08-16 17:08                 ` Eli Zaretskii
2020-08-16 15:05           ` Óscar Fuentes
2020-08-15 22:34       ` Paul Eggert
2020-08-16  2:31         ` Eli Zaretskii
2020-08-16 15:25           ` Paul Eggert
2020-08-16 15:39             ` Eli Zaretskii
2020-08-17  4:21               ` Paul Eggert [this message]
2020-08-17 16:21                 ` Eli Zaretskii

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=c2404915-e179-9935-baf8-7af4cda76b91@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=andrewjmoreton@gmail.com \
    --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).