help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: insert-header-preprocessor-definition


From: Ben Bacarisse
Subject: Re: insert-header-preprocessor-definition
Date: Wed, 11 Apr 2018 16:47:15 +0100

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 via email to

[Prev in Thread] Current Thread [Next in Thread]