Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
<Samples> Pointers to functions
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post will appear after it is approved by moderators
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alex Vinokur  
View profile  
 More options Nov 20 2006, 12:34 pm
From: Alex Vinokur <ale...@users.sourceforge.net>
Date: Mon, 20 Nov 2006 19:34:34 +0200
Local: Mon, Nov 20 2006 12:34 pm
Subject: <Samples> Pointers to functions

// ==========================================
// * Samples
// * Pointers to functions
// * Version 2.0
// ------------------------------------------
// * Language : C
// * Content  : Program file
// ------------------------------------------
// * Attachment
//   - pointers-to-functions.c
// ==========================================

 Alex Vinokur
     email: alex DOT vinokur AT gmail DOT com
     http://mathforum.org/library/view/10978.html
     http://sourceforge.net/users/alexvn

[ pointers-to-functions.c 2K ]
// ==========================================
// * Samples
// * Pointers to functions
// * Language : C
// * Version 2.0
// ==========================================

// ============ C-code: Begin ============

// --------------------------------------------------
char f1(int); // Declaration
char f1(int dummy) {return 'a';} // Implementation
char (*pf1) (int); // Variable

char *f2(int); // Declaration
char *f2(int dummy) { return (char*)0;} // Implementation
char *(*pf2)(int); // Variable

char (*f3(double)) (int); // Declaration
char (*f3(double d_dummy)) (int i_dummy) { return (char (*) (int))0;} // Implementation
char (*(*pf3)(double)) (int); // Variable
// --------------------------------------------------

// ===================================================================
// f1 is a 'function' that returns 'char' and takes an 'int-argument'.
// pf1 is a 'pointer-to-function'; the function returns 'char' and takes an 'int-argument'.

// f2 is a 'function' that returns 'pointer-to-char' and takes an 'int-argument'.
// pf2 is a 'pointer-to-function'; the function returns 'pointer-to-char' and takes an 'int-argument'.

// f3 is a 'function-1' that returns 'pointer-to-function-2' and takes a 'double-argument';
//         'function-2' returns 'char' and takes 'int-argument'.
// pf3 is a 'pointer-to-function-1'; the function-1 returns 'pointer-to-function-2' and takes a 'double-argument';
//         'function-2' returns 'char' and takes 'int-argument'.
// ===================================================================

// ---------------------------------------
typedef char (*pfunc_t1) (int);
typedef char *(*pfunc_t2) (int);
typedef char (*(*pfunc_t3)(double)) (int);
// ---------------------------------------

int main ()
{
char     ch;
char*    pch;

char (*pf4) (int);

pfunc_t1 pfunc1 = f1;
pfunc_t2 pfunc2 = f2;
pfunc_t3 pfunc3 = f3;
pfunc_t1 pfunc4;

  ch  = pf1 (1100);
  pch = pf2 (1200);
  pf4 = pf3 (1300.1);
  ch  = pf4 (1400);
  ch  = pf3 (1500.1)(1600);

  ch     = pfunc1 (2100);
  pch    = pfunc2 (2200);
  pfunc4 = pfunc3 (2300.1);
  ch     = pfunc4 (2400);
  ch     = pfunc3 (2500.1)(2600);

  return 0;


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google