You are on page 1of 3

Hide Function Pointer Declarations With a typedef

file:///Users/saumitre/other/read/tech/c-func-ptrs-typedef.htm

IT Professionals Developers Solutions eBook Library Webopedia Login Register

Not sure if you have an account?


Include Code

Search Tips

TODAY'S HEADLINES | ARTICLE ARCHIVE | SKILLBUILDING | TIP BANK | SOURCEBANK | FORUMS | NEWSLETTERS

Specialized Dev Zones


Vendor Solutions

Average Rating: 4.4/5 | Rate this item | 111 users have rated this item.

eBook Library NEW


Webcasts
.NET
Java
C++
Web Dev
Architecture
Database
Security

Expertise: Advanced
Language: C++
March 8, 2000
Hide Function Pointer Declarations With a typedef
Can you tell what the following declaration means?

Open Source
XML
Semantic Web
VB Classic
ASP/ASP.NET
Enterprise
Mobile

void (*p[10]) (void (*)() );

Only few programmers can tell that p is an "array of 10 pointers to a function returning void and taking a
pointer to another function that returns void and takes no arguments." The cumbersome syntax is nearly
indecipherable. However, you can simplify it considerably by using typedef declarations. First, declare a
typedef for "pointer to a function returning void and taking no arguments" as follows:

Special Reports
10-Minute Solutions
DevXtra Editors' Blog
Shop DevX

typedef void (*pfv)();

Next, declare another typedef for "pointer to a function returning void and taking a pfv" based on the
typedef we previously declared:

APIfinder

typedef void (*pf_taking_pfv) (pfv);

Partners & Affiliates


Data Centers Data
Centers
prepaid calling card
prepaid calling card
Run Cloud Apps Run
Cloud Apps
Lean App Platform Lean
App Platform
Phone Cards Phone
Cards
Desktop Computers
Desktop Computers
Business Email Business
Email
IT Legal Contracts IT
Legal Contracts
Data Center Data Center
PDA Phones & Cases
PDA Phones & Cases
Cell Phones Cell Phones
Car Donations Car
Donations
Dedicated Servers
Dedicated Servers
Liability Insurance Liability
Insurance

Google Site Search


Help site visitors find
the right information
quickly.

Now that we have created the pf_taking_pfv typedef as a synonym for the unwieldy "pointer to a function
returning void and taking a pfv", declaring an array of 10 such pointers is a breeze:
pf_taking_pfv p[10];
Danny Kalev
If you have a hot tip and we publish it, we'll pay you. However, due to accounting overhead we no longer pay $10 for a single tip
submission. You must accumulate 10 acceptable tips to receive payment. Be sure to include a clear explanation of what the
technique does and why it's useful. If it includes code, limit it to 20 lines if possible. Submit your tip here.
DevX: C++ Zone

Browse "C++" Tips

Browse All Tips

Please rate this item (5=best)


1

By raviparu

December 8 2009 2:17 AM PDT

This example really helps in simplifying any sort of complex function pointer declarations
Reply to this comment

Add a comment
Enter a username
Email address (used only for verification; it will not be displayed or added to any list)

Google Site Search

Please type the alphanumeric characters above. What's this?

1 of 3

9/11/15, 12:13 PM

Hide Function Pointer Declarations With a typedef

Help site visitors find


the right information
quickly.

file:///Users/saumitre/other/read/tech/c-func-ptrs-typedef.htm

I cannot read this. Please generate a New image


Your comment:

(Maximum characters: 1200). You have 1200

characters left. HTML characters will not be displayed.

I agree to the Terms of Use


Need help?
Acceptable Use Policy

By raviparu

December 8 2009 2:17 AM PDT

This example really helps in simplifying any sort of complex function pointer declarations
Reply to this comment

Add a comment
Enter a username
Email address (used only for verification; it will not be displayed or added to any list)

Please type the alphanumeric characters above. What's this?


I cannot read this. Please generate a New image
Your comment:

(Maximum characters: 1200). You have 1200

characters left. HTML characters will not be displayed.

I agree to the Terms of Use


Need help?
Acceptable Use Policy

World's Fastest Object Database.

World's Fastest Object Database.

Intel Parallel Studio helps C++ developers find latent memory errors that
cause crashes and lockups Intel Parallel Studio helps C++ developers find
latent memory errors that cause crashes and lockups
Intel Parallel Studio helps C++ developers add parallelism to apps to take
advantage of multicore. Intel Parallel Studio helps C++ developers add
parallelism to apps to take advantage of multicore.
Intel Atom Developer Windows Beta 3 SDK Brings Enhancements & Component
Integration Intel Atom Developer Windows Beta 3 SDK Brings Enhancements
& Component Integration
C++ developers use Intel Parallel Studio to locate and optimize hotspots and
boost performance. C++ developers use Intel Parallel Studio to locate and
optimize hotspots and boost performance.

2 of 3

9/11/15, 12:13 PM

Hide Function Pointer Declarations With a typedef

file:///Users/saumitre/other/read/tech/c-func-ptrs-typedef.htm

Advertising Info | Permissions | Help | Site Map | Network Map | About

The Network for Technology Professionals

Search:
About Internet.com
Copyright 2015 QuinStreet Inc. All Rights Reserved. Copyright 2010 QuinStreet Inc. All Rights Reserved.
Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Solutions
Whitepapers and eBooks
PDF: Security Reference Guide
PDF: Data and Identity Security
PDF: Secure Remote Access 101

Helpful Cloud Computing Resources


MORE WHITEPAPERS, EBOOKS, AND ARTICLES

Webcasts
User Experience Management Indicators for Business and IT Success
Ensuring Performance Meets Business and Web User Needs

MORE WEBCASTS, PODCASTS, AND VIDEOS

Downloads and eKits


IBM DB2 e-kit for Database Professionals: Extending Skills is Fast and Easy
Get BlackBerry Enterprise Server Express for Free

MORE DOWNLOADS, EKITS, AND FREE TRIALS

Tutorials and Demos


Demo: Google Site Search
Virtual Event: Master Essential Techniques for Leveraging the Cloud
Article: Explore Application Lifecycle Management Tools in Visual Studio 2010
Internet.com Hot List: Get the Inside Scoop on IT and Developer Products

3 of 3

New Security Solutions Using Intel(R) vPro(TM) Technology


All About Botnets
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES

9/11/15, 12:13 PM

You might also like