Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4064802
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:54:10+00:00 2026-05-20T15:54:10+00:00

For C header files, you can prevent multiple inclusion of a header file like:

  • 0

For C header files, you can prevent multiple inclusion of a header file like:

#ifndef MY_FOO_H
#define MY_FOO_H

[...]

#endif

How can I do the same thing in m4 such that multiple include() macro calls to the same file will only cause the contents to be included once?

Specifically, I want to do an ifdef guard that involves using macro changequote ( I’ll not clutter my code with dnl‘s):

Originally, when I do the following, multiple inclusions still corrupts the quotes:

changequote_file.m4:

ifdef(my_foo_m4,,define(my_foo_m4,1)
changequote([,])
)

changequote_invocation.m4:

include(changequote_file.m4)
After first include invocation:
[I should not have brackets around me]
`I should have normal m4 quotes around me'
include(changequote_file.m4)
After second include invocation:
[I should not have brackets around me]
`I should have normal m4 quotes around me'

Invoked with m4 changequote_invocation.m4 yields:

After first include invocation:
I should not have brackets around me
`I should have normal m4 quotes around me'


After second include invocation:
[I should not have brackets around me]
`I should have normal m4 quotes around me'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:54:10+00:00Added an answer on May 20, 2026 at 3:54 pm

    The most straightforward way is an almost-literal translation of the cpp version:

    ifdef(`my_foo_m4',,`define(`my_foo_m4',1)dnl
    (rest of file here)
    ')dnl
    

    So if my_foo_m4 is defined, the file expands to nothing, otherwise its contents are evaluated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using Eclipse+CDT+SVN(Linux). How can we have some common header files in a
can we declare a function in a header file in following way? extern int
Given a function, let's say atoi, how can I find the header file I
I'm wondering how can I put a header into my PDF file, cause I've
Suppose I have #define foo in various header files. It may expand to some
I have a download script that processes my downloads: download.php?file=file_refrence_here How can I prevent
My C headers usually resemble the following style to avoid multiple inclusion: #ifndef <FILENAME>_H
I have one .cpp file that includes a few header files. These header files
how can i determine the file name in header when i get with php.
What harm can come from defining BOOST_DISABLE_ABI_HEADERS when compiling boost? From the boost file:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.