Function Question

Discussion in 'C++' started by Bryan Parkoff, Sep 19, 2004.

  1. Do C/C++ Compiler allow function to contain more than 8 parameters? I
    checked MS Visual C++ 6.0 that it can only limit 8 parameters, but
    most C/C++ Compiler can limit maximum 256 parameters. Can you please
    verify for me?
    Usually, I write function that is about 100 lines. I would need
    20 parameters which they are all reference to global variable inside
    struct. For best optimization, it does not require to create stack
    frame because variables are always global inside struct. It is
    possible that stack frame is never created because local variables are
    never defined.
    I like pointer to function into array that it looks like CALL
    Table, but I prefer to use switch cases that it looks like JMP Table
    because all functions under pointer list can't be inlined or
    forceinlined, but only sub-functions can be inlined or forceinlined
    inside pointer to function list.
    Are you sure that pointer to function list can only limit to 1,023
    while switch cases can limit to 300 or 1,023 for best optimization?
    I have another problem with #define, #undef, and #ifdef directive
    inside functions. I have three duplicated functions with 10 lines.
    First function has 8 lines, Second function has 9 lines. Third
    function has 10 lines. I prefer to use only one function so #ifdef
    name and #endif will be placed on line 9 and line 10.
    Most functions can have #define and #undef before it starts to
    call function with 10 lines. If #undef is executed, 9th line and/or
    10th line will be ignored. I tried to test, but it seems not working.
    It accepts to execute 9th line and 10th line while #undef is
    executed. I don't know why.
    Do I have to accept the fact that I can't use #define and #undef
    inside most functions before it calls function with 10 lines? Then, I
    am advised to create 3 duplicated functions -- 8 lines, 9 lines, and
    10 lines. Most functions will have pointer to function that can
    choose to point one of three duplicated functions. The problem is
    that I want 3 functions to be forceinlined for best performance
    because pointer to function does not allow. If I try, I will get
    error message saying, inline or forceinlined must be removed before it
    is compiled.
    Please advise what I have to do other option.

    --
    Bryan Parkoff
    Bryan Parkoff, Sep 19, 2004
    #1
    1. Advertising

  2. Bryan Parkoff

    George Guest

    Please advise? how about "get a job" troll-****....


    "Bryan Parkoff" <> wrote in message
    news:...
    > Do C/C++ Compiler allow function to contain more than 8 parameters? I
    > checked MS Visual C++ 6.0 that it can only limit 8 parameters, but
    > most C/C++ Compiler can limit maximum 256 parameters. Can you please
    > verify for me?
    > Usually, I write function that is about 100 lines. I would need
    > 20 parameters which they are all reference to global variable inside
    > struct. For best optimization, it does not require to create stack
    > frame because variables are always global inside struct. It is
    > possible that stack frame is never created because local variables are
    > never defined.
    > I like pointer to function into array that it looks like CALL
    > Table, but I prefer to use switch cases that it looks like JMP Table
    > because all functions under pointer list can't be inlined or
    > forceinlined, but only sub-functions can be inlined or forceinlined
    > inside pointer to function list.
    > Are you sure that pointer to function list can only limit to 1,023
    > while switch cases can limit to 300 or 1,023 for best optimization?
    > I have another problem with #define, #undef, and #ifdef directive
    > inside functions. I have three duplicated functions with 10 lines.
    > First function has 8 lines, Second function has 9 lines. Third
    > function has 10 lines. I prefer to use only one function so #ifdef
    > name and #endif will be placed on line 9 and line 10.
    > Most functions can have #define and #undef before it starts to
    > call function with 10 lines. If #undef is executed, 9th line and/or
    > 10th line will be ignored. I tried to test, but it seems not working.
    > It accepts to execute 9th line and 10th line while #undef is
    > executed. I don't know why.
    > Do I have to accept the fact that I can't use #define and #undef
    > inside most functions before it calls function with 10 lines? Then, I
    > am advised to create 3 duplicated functions -- 8 lines, 9 lines, and
    > 10 lines. Most functions will have pointer to function that can
    > choose to point one of three duplicated functions. The problem is
    > that I want 3 functions to be forceinlined for best performance
    > because pointer to function does not allow. If I try, I will get
    > error message saying, inline or forceinlined must be removed before it
    > is compiled.
    > Please advise what I have to do other option.
    >
    > --
    > Bryan Parkoff
    George, Sep 19, 2004
    #2
    1. Advertising

  3. Bryan Parkoff

    lallous Guest

    Hello Bryan,

    "Bryan Parkoff" <> wrote in message
    news:...
    > Do C/C++ Compiler allow function to contain more than 8 parameters? I
    > checked MS Visual C++ 6.0 that it can only limit 8 parameters, but
    > most C/C++ Compiler can limit maximum 256 parameters. Can you please
    > verify for me?
    > Usually, I write function that is about 100 lines. I would need
    > 20 parameters which they are all reference to global variable inside
    > struct. For best optimization, it does not require to create stack
    > frame because variables are always global inside struct. It is
    > possible that stack frame is never created because local variables are
    > never defined.
    > I like pointer to function into array that it looks like CALL
    > Table, but I prefer to use switch cases that it looks like JMP Table
    > because all functions under pointer list can't be inlined or
    > forceinlined, but only sub-functions can be inlined or forceinlined
    > inside pointer to function list.
    > Are you sure that pointer to function list can only limit to 1,023
    > while switch cases can limit to 300 or 1,023 for best optimization?


    I don't think the standard should be dictating any limit on how much a
    function can take as max parameters.

    VC++ 6, for sure, allows more than 8 params.

    > I have another problem with #define, #undef, and #ifdef directive
    > inside functions. I have three duplicated functions with 10 lines.
    > First function has 8 lines, Second function has 9 lines. Third
    > function has 10 lines. I prefer to use only one function so #ifdef
    > name and #endif will be placed on line 9 and line 10.
    > Most functions can have #define and #undef before it starts to
    > call function with 10 lines. If #undef is executed, 9th line and/or
    > 10th line will be ignored. I tried to test, but it seems not working.
    > It accepts to execute 9th line and 10th line while #undef is
    > executed. I don't know why.


    I don't know if you know that #ifdef/#undef will only allow a certain part
    of the code to be compiled while the code that didn't fulfill your condition
    won't exist at all. Unlike "if/else" which are runtime checks.

    If you still want to write one function, just add an extra parameter to your
    function as:
    int threeinon(int x, int y, int whatfunction)

    then inside this function check for 'whatfunction' value and see if you need
    to execute a certain addition code.

    you may want to use "structs and unions" to build a struct that can be
    passed as a param to "threeinon" so that each version of that function can
    have its own set of parameters.

    > Do I have to accept the fact that I can't use #define and #undef
    > inside most functions before it calls function with 10 lines? Then, I
    > am advised to create 3 duplicated functions -- 8 lines, 9 lines, and
    > 10 lines.


    How you mean, it...Show some code please.

    > Most functions will have pointer to function that can
    > choose to point one of three duplicated functions. The problem is
    > that I want 3 functions to be forceinlined for best performance
    > because pointer to function does not allow. If I try, I will get
    > error message saying, inline or forceinlined must be removed before it
    > is compiled.
    > Please advise what I have to do other option.


    If you're using VC++ and its features (which might not apply to other
    compilers) then it is advised to repost your question to appropriate
    newsgroup.

    This list targets platform independent C++ issues.

    Regards,
    Elias
    lallous, Sep 19, 2004
    #3
  4. Bryan Parkoff wrote:

    > Do C/C++ Compiler allow function to contain more than 8 parameters? I
    > checked MS Visual C++ 6.0 that it can only limit 8 parameters, but
    > most C/C++ Compiler can limit maximum 256 parameters. Can you please
    > verify for me?
    > Usually, I write function that is about 100 lines. I would need
    > 20 parameters which they are all reference to global variable inside
    > struct. For best optimization, it does not require to create stack
    > frame because variables are always global inside struct. It is
    > possible that stack frame is never created because local variables are
    > never defined.

    The common practice is to place many parameters for a function into
    a structure, then pass the structure. A function that has more than
    5 parameters becomes unreadable.


    > I like pointer to function into array that it looks like CALL
    > Table, but I prefer to use switch cases that it looks like JMP Table
    > because all functions under pointer list can't be inlined or
    > forceinlined, but only sub-functions can be inlined or forceinlined
    > inside pointer to function list.
    > Are you sure that pointer to function list can only limit to 1,023
    > while switch cases can limit to 300 or 1,023 for best optimization?

    A table of function pointers is only limited by the memory of your
    machine or some compiler limit.

    I agree with what other people have stated in your first post: if
    you have that many selections, you design needs to be reviewed.


    > I have another problem with #define, #undef, and #ifdef directive
    > inside functions. I have three duplicated functions with 10 lines.
    > First function has 8 lines, Second function has 9 lines. Third
    > function has 10 lines. I prefer to use only one function so #ifdef
    > name and #endif will be placed on line 9 and line 10.
    > Most functions can have #define and #undef before it starts to
    > call function with 10 lines. If #undef is executed, 9th line and/or
    > 10th line will be ignored. I tried to test, but it seems not working.
    > It accepts to execute 9th line and 10th line while #undef is
    > executed. I don't know why.

    Sounds ugly. Here are some suggestions:
    1. Have a function that contains the common 8 lines.
    Have two functions that first call the 8 line function then perform
    their next lines.

    2. Consider using a Function Object or Functor. Place the 8 lines
    into a base class for the Functor. Create descendant functor
    classes that contain the additional code.


    > Do I have to accept the fact that I can't use #define and #undef
    > inside most functions before it calls function with 10 lines? Then, I
    > am advised to create 3 duplicated functions -- 8 lines, 9 lines, and
    > 10 lines. Most functions will have pointer to function that can
    > choose to point one of three duplicated functions. The problem is
    > that I want 3 functions to be forceinlined for best performance
    > because pointer to function does not allow. If I try, I will get
    > error message saying, inline or forceinlined must be removed before it
    > is compiled.
    > Please advise what I have to do other option.

    Show your code and indicate what you want the code to perform.


    --
    Thomas Matthews

    C++ newsgroup welcome message:
    http://www.slack.net/~shiva/welcome.txt
    C++ Faq: http://www.parashift.com/c -faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.comeaucomputing.com/learn/faq/
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
    Thomas Matthews, Sep 20, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Vanns
    Replies:
    7
    Views:
    7,035
    Evan Carew
    Jan 21, 2004
  2. komal
    Replies:
    6
    Views:
    1,419
    msalters
    Jan 25, 2005
  3. Replies:
    2
    Views:
    916
    Bengt Richter
    Aug 1, 2005
  4. Giannis Papadopoulos

    Function pointer to void function and int function

    Giannis Papadopoulos, Sep 5, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,236
    Barry Schwarz
    Sep 5, 2005
  5. weafon
    Replies:
    1
    Views:
    305
    Diez B. Roggisch
    Jul 14, 2009
Loading...

Share This Page