www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/24/10:15:30

From: br5an AT aol DOT com (Br5an)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: A dream.......
Date: 23 Sep 1997 21:14:49 GMT
Lines: 31
Message-ID: <19970923211401.RAA14413@ladder02.news.aol.com>
NNTP-Posting-Host: ladder02.news.aol.com
Organization: AOL http://www.aol.com
References: <3426DC53 DOT A4C1F40B AT sr DOT flashnet DOT it>
SnewsLanguage: English
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

>Is possible to pass operator as function parameter ?
>....like this fantasious example ??...

I'll put in 2 cents worth.  Something like this "might" be more straight
forward with a C++ class. However, since I don't know the circumstance I'll
post a C  idea.

int My_Func(int, int, char);

int main( )
{
   char oper;
   int a, b, c;
   
   oper = '+';
   a = 10;
   b = 5;
   c = My_Func(a, b, oper);
   return(0);
}

int My_Func(int a, int b, char ch)
{
   if(ch == '+')
      return(a + b);
   else
   if(ch == '-')
      return(a - b);
    .....            /*  you might even setup a switch( )  ?  */
}
      

- Raw text -


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