CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2002
    Posts
    3

    [C] void(*pfunc)(...);

    I have made a testprogram in Visual Studio, which uses a functionpointer like this:

    Str1, Str2 and Str3 contain the functionaddresses retreived out of the mapfile.

    #include "stdargs.h"

    void (*pfunc)(...);

    memcpy(&pfunc,Str1,4);
    pfunc();

    memcpy(&pfunc,Str2,4);
    pfunc(20);

    memcpy(&pfunc,Str3,4);
    pfunc(20, "test");

    This works great.

    But I really want to use this in an embedded ARM system. So I wrote the same code in an ANSI C file for ARM.
    For compiling I use the ADS compiler. But this compiler errors on the (...) in the pointer declaration.

    When I leave the ... away like this:

    void (*pfunc)();

    it does not come up with any errors. But I still call functions with 1 or 2 parameters.

    Can anyone tell me if this is possible in ANSI C?
    And if it is, is it a compiler bug or am I doing something wrong?

  2. #2
    Join Date
    Jun 2002
    Posts
    224

    Re: [C] void(*pfunc)(...);

    Standard C requires at least one fixed argument. So as you can start parsing the rest of arguments.

    Code:
    int foo( int arg1, ... )
    {
      va_list list;
      va_start(list, arg1 );
      /*...*/
    }
    ZDF

    What is good is twice as good if it's simple.
    "Make it simple" is a complex task.

  3. #3
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347

    Also ...

    ... in C, if you have NO function arguments in the declaration, that means the function can take any number of arguments; in C++, it means that the function takes NO arguments, I believe.

  4. #4
    Join Date
    Jun 2002
    Posts
    224

    Re: Also ...

    Originally posted by PaulWendt
    ... in C, if you have NO function arguments in the declaration, that means the function can take any number of arguments; in C++, it means that the function takes NO arguments, I believe.
    Does your compiler successfully compile the code below?
    Code:
    int foo(...)
    {
    }
    ZDF

    What is good is twice as good if it's simple.
    "Make it simple" is a complex task.

  5. #5
    Join Date
    Jun 2002
    Posts
    3

    Re: Re: Also ...

    Originally posted by zdf


    Does your compiler successfully compile the code below?
    Code:
    int foo(...)
    {
    }
    Yes it does. But my problem is already answered.

    ... in C, if you have NO function arguments in the declaration, that means the function can take any number of arguments; in C++, it means that the function takes NO arguments, I believe.

    This I did not know. I have not been able to find it either. THanks for the quick answers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured