Re: ifdef usage

Eric Blake <[email protected]>
Newsgroups gmane.comp.gnu.m4.general
Message-ID <[email protected]>
Eric Blake <ebb9 <at> byu.net> writes:

Aargh.  I typed my first answer too hastily.

> Incorrect quotes.  By default, m4 uses "`" and "'", not "'" and "'".  
> Therefore, you ended up defining a macro literally named "'VNC'", rather than 
> the intended "VNC".

This part still stands.

> 
> >    ifdef('VNC', 'vnc is DEFINED', 'vnc is NOT DEFINED')
> 
> M4 performs macro expansion during argument collection.  Since you aren't 
using 
> proper quote characters, this means that you effectively called:
> 
> ifdef(<expansion of 'VNC'>, ..., ...)

Correction.  ' is not part of a macro name, so you effectively called:

ifdef("'"<expansion of VNC>"'", ..., ...)

But since VNC is not a macro, that means you are checking the result of 
whether "'" concatenated with "VNC" concatenated with "'" is a macro, and 
indeed, "'VNC'" is a macro.

> > If I comment out the define(), and then do the following:
> > 
> >    bash% m4 -DVNC testing.m4
> >    #define('VNC')
> >    'vnc is NOT DEFINED'
> 
> Your command-line usage defined the macro "VNC", as you wanted.  Now 
> that "'VNC'" is not a macro, your ifdef usage is checking whether "'VNC'" is 
> defined, which it is not, still explaining your surprise.

Correction.  Here, "VNC" is a macro, which means you are checking whether "'" 
concatenated with its expansion ("") concatenated with "'" is a macro, and 
since "''" is not a macro, that explains your result.

-- 
Eric Blake
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.