Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!portal!cup.portal.com!Tim_CDC_Roberts From: Tim_CDC_Roberts@cup.portal.com Newsgroups: comp.lang.c Subject: Re: on the fringe of C syntax/semantics Message-ID: <22808@cup.portal.com> Date: 5 Oct 89 18:25:25 GMT References: <80100001@bonzo> <19971@mimsy.UUCP> <19987@mimsy.UUCP> Organization: The Portal System (TM) Lines: 23 Re: How do I write a cast to a function pointer etc.? Within the past few months, one of the gurus here posted a quick rule for figuring out how to write a cast, which I made myself read over and over until I memorized it. To make a cast for a given simple or complex type, first write a declaration of some "thing" of that type: int * (* func)(); func is ptr to function returning ptr to int Then, remove the name of the "thing" and surround the declaration with parentheses. This becomes the cast: (int * (*)()) x x is cast to ptr to function returning ptr to int This method is so simple and elegant (and not intuitively obvious to a beginning-to-intermediate C programmer), that it deserves to be in that list of "Commonly asked C Questions", whenever someone gets around to putting it together. Tim_CDC_Roberts@cup.portal.com | Control Data... ...!sun!portal!cup.portal.com!tim_cdc_roberts | ...or it will control you.