Re: Recommended m4 macro naming convention?

Eric Blake <[email protected]> Fri, 02 May 2014 06:13:36 -0600
Newsgroups gmane.comp.gnu.m4.general
Organization Red Hat, Inc.
Message-ID <[email protected]>
On 05/02/2014 12:33 AM, Daniel Goldman wrote:
> This may seem a silly question to some, but I think naming conventions
> are important. So, any advice concerning naming conventions for m4 macro
> names, eg foo_bar, fooBar, Foo_Bar, FOO_BAR, etc?
> 
> [A-Z_a-z][A-Z_a-z0-9]* is the requirement for m4 macro names, I hope I
> got that right, :) so that is not my question.

Yes, you got that right.

> 
> In cpp, the strong standard is UPPER_CASE, such as:
> 
> #define ANALYZES_AGES_UNDER_ONE__________TF FALSE
> 
> Of course cpp doesn't care, allows same names as m4. But it is
> reassuring to always see UPPER_CASE, a dead giveaway for cpp macros.
> 
> In the GNU m4 manual, all the builtin macros are lowercase, and the
> examples almost all use lowercase macro names. But an example from the
> Gnulib project uses uppercase. sendmail seems to use at least a few
> uppercase macros, maybe a lot. Some postings on this group use uppercase
> names. My cpp experience makes me want to use UPPER_CASE. Is there any
> general guideline, or is it just "whatever you like"? If no general
> guideline, should there be?

m4 is used in so many different contexts, and the language itself
doesn't care, so it is really up to your application to choose a
convention.  But yes, autoconf recommends ALL_CAPS, or possibly
sig_ALL_CAPS (where sig_ represents a lowercase namespace for a set of
macros provided from a single source), as the easiest to recognize.
Although the builtins default to lower case, m4 lets you rename the
builtins to whatever naming convention you'd like.

> 
> Could one argue builtins behave like "functions" (I know they are
> macros), so maybe use lower_case for user-defined macros with "function"
> behavior (just like some C lowercase macros, eg, isascii), and use
> UPPER_CASE for "pure" macros (simple substitution)?

Again, that's more up to your project, and what you want to document and
maintain for your local use of m4.

-- 
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 v1
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBCAAGBQJTY4vwAAoJEKeha0olJ0NqtAMH/1PRtbO/JYNM/XH/seR0mz4H
g3SFkv9d2D0snvIa5TCN4TJVWg4RTdp8m21WbZ2yL9qVpcHPR0qU63gcKSAGrgHX
lfgrtCPhy/Pm0JPycLU9aYr1HSKmu89q4eSjO3OTieMcmm2o5qmohZAKDG4oqYi1
CpDywsRjBM8w2CKwXIWEdre/yQSxbhQFqeTSAXcEck7AWA4Qq1UFK/bjteodWJcy
tOAdDcZstO8z4nM7vqH4zqpEwrNEpMF8rAQGq2saeNIoQmSJSb7RHXk0HmgMQYBf
h/0QsjitCXCJE5DzGTHzia23jwqCaxA7eqVZNtuDkzpfP2Y7XIlyqF9V8tmt+oo=
=6yk3
-----END PGP SIGNATURE-----