unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Ben Bacarisse <ben.usenet@bsb.me.uk>
To: help-gnu-emacs@gnu.org
Subject: Re: insert-header-preprocessor-definition
Date: Wed, 11 Apr 2018 16:47:15 +0100	[thread overview]
Message-ID: <87lgdt21a4.fsf@bsb.me.uk> (raw)
In-Reply-To: 86fu429udy.fsf@zoho.com

Emanuel Berg <moasen@zoho.com> writes:

> (defun insert-header-preprocessor-definition ()
>   (interactive)
>   (let*((filename (buffer-name))
>         (label (upcase (replace-regexp-in-string "\\." "_" filename)))

It's off-topic, but this common construction can give rise to C's
dreaded "undefined behaviour".  All sorts of macro names are reserved to
the implementation depending on what headers have been included in the
source file that includes this one.

It's common to ignore this rule, but if you are providing a facility for
general use it might be better to follow letter of the law.  Pre-pending
"H_" to the label is known to be safe.

>         (beg-string (concat
>                      (format "#ifndef %s\n"   label)
>                      (format "#define %s\n\n" label) ))

I'd probably write

  (concat "#ifndef " label "\n"
          "#define " label "\n\n")

or if I was not bothered about showing the separate lines:

  (format "#ifndef %s\n#define %s\n\n" label label),

<snip>
-- 
Ben.


       reply	other threads:[~2018-04-11 15:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <86fu429udy.fsf@zoho.com>
2018-04-11 15:47 ` Ben Bacarisse [this message]
2018-04-11 20:41   ` insert-header-preprocessor-definition Emanuel Berg
2018-04-11 20:56     ` insert-header-preprocessor-definition Ben Bacarisse
2018-04-11 22:07       ` insert-header-preprocessor-definition Emanuel Berg
2018-04-14 23:54       ` insert-header-preprocessor-definition Emanuel Berg
2018-04-15  1:02         ` insert-header-preprocessor-definition Ben Bacarisse
2018-04-15  7:44           ` insert-header-preprocessor-definition Yuri Khan
2018-04-15 19:35           ` insert-header-preprocessor-definition Emanuel Berg
2018-04-15 21:10             ` insert-header-preprocessor-definition Ben Bacarisse
2018-04-15 21:45               ` insert-header-preprocessor-definition Emanuel Berg
     [not found]           ` <mailman.12420.1523778312.27995.help-gnu-emacs@gnu.org>
2018-04-15 19:46             ` insert-header-preprocessor-definition Emanuel Berg
2018-04-16  5:35               ` insert-header-preprocessor-definition Yuri Khan
     [not found]               ` <mailman.12486.1523856961.27995.help-gnu-emacs@gnu.org>
2018-04-16  6:16                 ` insert-header-preprocessor-definition Emanuel Berg

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=87lgdt21a4.fsf@bsb.me.uk \
    --to=ben.usenet@bsb.me.uk \
    --cc=help-gnu-emacs@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.
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).