Re: Help on M4 Usage

Eric Blake <[email protected]> Fri, 29 Apr 2016 09:46:45 -0600
Newsgroups gmane.comp.gnu.m4.general
Organization Red Hat, Inc.
Message-ID <[email protected]>
[top-posting on technical lists makes it harder to follow the conversation]

On 04/29/2016 09:17 AM, Nidhin Joseph wrote:
> Hi,
>  Yes. I understand your point. But I would like to clear one more doubt. Is
> it possible to prevent macro expansion if the key is quoted?
> 
> For example,
>   - getApproximateValue(MY_CUSTOM_KEY) should be converted to
> getApproximateValue(50)
>   - getApproximateValue("MY_CUSTOM_KEY") should remain as
> getApproximateValue("MY_CUSTOM_KEY")

The only way to make M4 not do macro expansion is to use m4 quotes; if
your source file uses

getApproximateValue(`"MY_CUSTOM_KEY"')

(assuming you didn't use changequote() to change the m4 quoting to
something else), then the expansion will be:

getApproximateValue("MY_CUSTOM_KEY")

regardless of whether MY_CUSTOM_KEY is a macro.  But unlike the C
preprocessor, m4 does not have a way to identify C strings where macros
are not to be expanded.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc (application/pgp-signature, 604 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBCAAGBQJXI4HlAAoJEKeha0olJ0Nq9+EH/3JpS5XbLtnKu5oBSbDdSiZp
vpFdkEGLcR8z9P4+91IJ8vgonWOLepytvjMbnXSf+h+WRXhgZjhFrpn5MpJtL5tK
1gHhwV/M2JKJQXhu0a+X2eLzeXLJPHacM8EEHKlME8AwXraHsKU+7Bt7WObL20ZM
22dvNRPUp1N72DoeNHLObAzT1B2QiOR8ruVle8jSKihbOJV/8T0dfI6pGOwFL5pJ
OHPqHwezaF88lJkZs2b4wG4JnlGlUK/NOG9rLjj4Nuwowxe4woclCjngDRpllrSC
02xP0lrTulqsVcnXBMONRMk/AVCJ/d81JqBMXrh1tRkSs3UmqsQMI1Fjfqko2bA=
=dzbi
-----END PGP SIGNATURE-----