Re: Strange C constructs

iddw@hotmail.com (Dave Hansen)
27 Feb 2004 22:11:21 -0500

          From comp.compilers

Related articles
Strange C constructs vbdis@aol.com (2004-02-26)
Re: Strange C constructs derek@NOSPAMknosof.co.uk (Derek M Jones) (2004-02-26)
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)
[2 later articles]
| List of all articles for this month |

From: iddw@hotmail.com (Dave Hansen)
Newsgroups: comp.compilers
Date: 27 Feb 2004 22:11:21 -0500
Organization: Compilers Central
References: 04-02-147
Keywords: C
Posted-Date: 27 Feb 2004 22:11:21 EST

On 26 Feb 2004 01:08:58 -0500, vbdis@aol.com (VBDis) wrote:


>My selfmade C preprocessor stumbled across a strange construct in one of the
>Windows headers. Now I would like to know whether this really makes sense:
>
>#define something /##/
>
[...]
>
>Is this construct really a stupid Microsoft extension, intended to prevent the
>compilation of Windows code with other compilers, or did I miss something in
>the newer C specs?


Although I won't speculate on their motivation, you are correct that
this is nonstandard and an error. Specifically, comments are replaced
by whitespace in phase 3, and preprocessing directives are executed in
phase 4.


>Another question may be easier to answer:
>
>typedef int (procname)(int arg);
>
>According to K&R only /pointers/ to procedure-types can be constructed. Does
>there exist newer specs which allow to typedef procedures themselves?


The above defines a type, specifically "procname", which is a function
taking an int and returning an int. This is perfectly legal. (The
parens around "procname" aren't required.)


However, you can't use the unadorned type to define an object for
function. For example


      procname echo
      {
            return arg;
      }


doesn't work.


You can only use it to define other types, e.g.


      procname *f_ptr;
      typedef procname *procptr;
      procptr p_ptr;


are all OK.


Regards,


                                                              -=Dave


Post a followup to this message

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