www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/01/01:19:41

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Array of functions?
Date: Sun, 31 Aug 1997 14:56:13 -0700
Organization: Alcyone Systems
Lines: 22
Message-ID: <3409E87D.7A81AACF@alcyone.com>
References: <34086133 DOT 3E0C AT compuserve DOT com>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Jason Meehan wrote:

> How would I declare An array of A function?
> Thanks.

In C there's no such concept as an array of functions, but you can
declare (and use) an array of _pointers_ to functions:

    extern int f(void), g(void), h(void);
    extern int (*fa[])(void) = { f, g, h };
    int i, ret;

    for (i = 0; i < sizeof fa/sizeof fa[0]; i++)
        ret = (*fa[i])(); /* or ret = (fa[i])(); */

-- 
          Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com
                        Alcyone Systems / http://www.alcyone.com/max/
   San Jose, California, United States / icbm://37.20.07n/121.53.38w
                                      \
                  "War is like love; / it always finds a way."
                                    / Bertolt Brecht

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019