From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: gmane.emacs.help Subject: Re: insert-header-preprocessor-definition Date: Wed, 11 Apr 2018 16:47:15 +0100 Organization: A noiseless patient Spider Message-ID: <87lgdt21a4.fsf@bsb.me.uk> References: <86fu429udy.fsf@zoho.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1523461851 5287 195.159.176.226 (11 Apr 2018 15:50:51 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 11 Apr 2018 15:50:51 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Apr 11 17:50:47 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f6I1H-0001Hq-D7 for geh-help-gnu-emacs@m.gmane.org; Wed, 11 Apr 2018 17:50:47 +0200 Original-Received: from localhost ([::1]:36293 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6I3O-0002A1-3K for geh-help-gnu-emacs@m.gmane.org; Wed, 11 Apr 2018 11:52:58 -0400 Original-Path: usenet.stanford.edu!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 32 Original-Injection-Info: reader02.eternal-september.org; posting-host="2586ae6ef9c72e9e16b31e16921940a1"; logging-data="11019"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/R3B8ib8AcDy0kvXejvdKqJTnvm+Xaz9g=" Cancel-Lock: sha1:22wlFTCgPShaiBZqGK67nl5HipQ= sha1:wbYx03oebUI3wsuX4GxC1i/WkmM= X-BSB-Auth: 1.813fc421e5711817a42a.20180411164715BST.87lgdt21a4.fsf@bsb.me.uk Original-Xref: usenet.stanford.edu gnu.emacs.help:222345 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:116463 Archived-At: Emanuel Berg 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), -- Ben.