Re: Strange C constructs

Victor Zverovich <viz@pisem.net>
2 Mar 2004 11:15:38 -0500

          From comp.compilers

Related articles
[2 earlier articles]
Re: Strange C constructs iddw@hotmail.com (2004-02-27)
Re: Strange C constructs jeremy@jdyallop.freeserve.co.uk (Jeremy Yallop) (2004-02-27)
Re: Strange C constructs alexc@std.com (Alex Colvin) (2004-02-27)
Re: Strange C constructs derek@NOSPAMknosof.co.uk (Derek M Jones) (2004-03-02)
Re: Strange C constructs david.thompson1@worldnet.att.net (Dave Thompson) (2004-03-02)
Re: Strange C constructs vbdis@aol.com (2004-03-02)
Re: Strange C constructs viz@pisem.net (Victor Zverovich) (2004-03-02)
Re: Strange C constructs RLake@oxfam.org.pe (2004-03-06)
Re: Strange C constructs nmm1@cus.cam.ac.uk (2004-03-11)
| List of all articles for this month |

From: Victor Zverovich <viz@pisem.net>
Newsgroups: comp.compilers
Followup-To: comp.lang.c
Date: 2 Mar 2004 11:15:38 -0500
Organization: NTLab
References: 04-02-147
Keywords: C
Posted-Date: 02 Mar 2004 11:15:38 EST

V> My selfmade C preprocessor stumbled across a strange construct in one of the
V> Windows headers. Now I would like to know whether this really makes sense:


V> #define something /##/


V> I can imagine that the intended effect is the creation of an comment
V> (// ...) in the source code, but IMO this is not achievable in
V> accordance to any C/C++ standard. An traditional preprocessor doesn't
V> recognize the ## operator, and newer preprocessors have to treat
V> comments before, or during, the tokenization, whereas the ## operator
V> is executing after tokenization, and there exists no valid
V> preprocessor token for "//".


V> Is this construct really a stupid Microsoft extension, intended to prevent the
V> compilation of Windows code with other compilers, or did I miss something in
V> the newer C specs?


The newest C99 standard introduces single line comments (//...), but
it can be formed in such a way using macro substitution and glueing.
It is shown in the following example stolen from the standard:


      #define glue(x,y) x##y
      glue(/,/) k(); // syntax error, not comment


K&R and previous C standard doesn't have such type of comment.
So this code (AFAIK it is located in WTypes.h) is completely illegal
in C and intended for use with brain-damadged Microsoft compilers.


V> typedef int (procname)(int arg);


V> According to K&R only /pointers/ to procedure-types can be constructed. Does
V> there exist newer specs which allow to typedef procedures themselves?


According to C99 standard this is legal, though you can't use this
typename (procname in this case) to define a function:


      procname f { return 0; } // illegal
      procname *f; // ok - f is a pointer to function


viz


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.