Thread: functions

  1. #1
    Caution: Wet Floor
    Join Date
    May 2006
    Posts
    55

    functions

    "Write the definition of a function that takes such a pointer as an argument and returns its argument as the return value."

    Code:
    // decs2.cc
    int main() {
     
      void f1(char*, int&);
      void (*pf1)(char*, int&);
    
      typedef void (*PF1) (char*, int&);
      typedef void (*PF1_ARG) (char*, int&);
    
      PF1 rp_pf1(PF1_ARG a) { // no good
         return a;
      }
    
    
    
    }
    Output:
    Code:
    decs2.cc: In function `int main()':
    decs2.cc:11: syntax error before `{' token
    Thanks.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Why the complication? Use a normal pointer like int* or something.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Caution: Wet Floor
    Join Date
    May 2006
    Posts
    55
    Oops, sorry.

    The "such a pointer" is

    "a pointer to a function taking arguments of type pointer to character and reference to integer and returning no value"

    which is a

    Code:
    void (*pf) (char*, int&)

    I think...

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Your code is basically right, but nested functions are undefined. Move it outside main.
    Code:
    typedef void (MyFunctionPtr)(char*, int&);
    
    MyFunctionPtr* Help2(MyFunctionPtr* p)
    {
    	return p;
    }
    
    void Help3(char* p, int& n)
    {
    }
    
    int main()
    {
    	Help2(&Help3);
    	return 0;
    }
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Caution: Wet Floor
    Join Date
    May 2006
    Posts
    55
    Your code is basically right, but nested functions are undefined.
    Oh.

    Thanks! It's working fine now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM