From: Nobody on
I don't think template functions work in this case, but I see that the Boost
library has constructs that allow looping.

Thank you

"Igor Tandetnik" <itandetnik(a)mvps.org> wrote in message
news:u4Z7mMKuKHA.3408(a)TK2MSFTNGP06.phx.gbl...
Nobody wrote:
> I am implementing a callback function for multiple callbacks, but the
> callback function does not have a parameter such as a handle or number to
> tell which callback the call is for. I have no control over it, so I can't
> add my own parameters, so I have to provide different entry points that
> calls a centralized routine with a sequence number. So I have functions
> like
> this:
>
> int func0(int para1,int para2) { return func(0,para1,para2);};
> int func1(int para1,int para2) { return func(1,para1,para2);};
> int func2(int para1,int para2) { return func(2,para1,para2);};
> int func3(int para1,int para2) { return func(3,para1,para2);};
>
> I plan to use a macro like this to generate the above using the
> Token-Pasting Operator (##):

Consider a template instead:

template <int seq>
int func(int para1, int para2) { return func(seq, para1, para2); }

func<2>(42, 84);

> #define paster( n ) int func##n(int para1,int para2) { return
> func(##n,para1,para2);}

You don't need second ##. Drop it.

> Is there a way to repeatedly call the macro a fixed number of times?

Use the template, and you wouldn't need to. If for some strange reason you
insist on using macros, there might be something like this in Boost
Preprocessor library:

http://www.boost.org/doc/libs/1_42_0/libs/preprocessor/doc/index.html

--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily
a good idea. It is hard to be sure where they are going to land, and it
could be dangerous sitting under them as they fly overhead. -- RFC 1925


From: Tim Roberts on
"Nobody" <nobody(a)nobody.com> wrote:
>
>Is there a way to repeatedly call the macro a fixed number of times?
>Something like #while or #for loop?

The short answer to your question is "no". You would need some external
tool do do this.

>Currently, I am using an Excel sheet to generate the code. Example:

Interesting choice. I would have chosen Python, or awk, or Perl, or even a
batch file, but Excel would never have occurred to me.
--
Tim Roberts, timr(a)probo.com
Providenza & Boekelheide, Inc.
From: Igor Tandetnik on
Nobody wrote:
> I don't think template functions work in this case

Why not, pray tell? Have you tried it?
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
From: Barry Schwarz on
On Sun, 28 Feb 2010 19:16:48 -0500, "Nobody" <nobody(a)nobody.com>
wrote:

>"Barry Schwarz" <schwarzb(a)dqel.com> wrote in message
>news:7chlo5hohjp5c56ij8h68tbvnl106nnsv0(a)4ax.com...
>> On Sun, 28 Feb 2010 13:00:59 -0500, "Nobody" <nobody(a)nobody.com>
>> wrote:
>>
>>>I am implementing a callback function for multiple callbacks, but the
>>>callback function does not have a parameter such as a handle or number to
>>>tell which callback the call is for. I have no control over it, so I can't
>>>add my own parameters, so I have to provide different entry points that
>>>calls a centralized routine with a sequence number. So I have functions
>>>like
>>>this:
>>>
>>>int func0(int para1,int para2) { return func(0,para1,para2);};
>>>int func1(int para1,int para2) { return func(1,para1,para2);};
>>>int func2(int para1,int para2) { return func(2,para1,para2);};
>>>int func3(int para1,int para2) { return func(3,para1,para2);};
>>>...
>>>
>>>I plan to use a macro like this to generate the above using the
>>>Token-Pasting Operator (##):
>>>
>>>#define paster( n ) int func##n(int para1,int para2) { return
>>>func(##n,para1,para2);}
>>
>> The preprocessor works on tokens. The purpose of the first ##
>> operator is to concatenate the literal func with the parameter n,
>> resulting in a single token (e.g., func1). What is the purpose of the
>> second ## operator? What would happen if you deleted it?
>
>I guess I should have used less confusing names. In the example, I have a
>central function func() to be called by func0(), func1(), func2(), etc.

That was perfectly clear. The point I was trying to get you to see is
that you are not creating a single token with the second ## operator.
It serves no purpose. The open parenthesis will always be a
stand-alone token. Removing the ## results in the exact same code
after substitution.

--
Remove del for email
From: Igor Tandetnik on
Barry Schwarz wrote:
> On Sun, 28 Feb 2010 19:16:48 -0500, "Nobody" <nobody(a)nobody.com>
> wrote:
>>>> #define paster( n ) int func##n(int para1,int para2) { return
>>>> func(##n,para1,para2);}
>
> That was perfectly clear. The point I was trying to get you to see is
> that you are not creating a single token with the second ## operator.
> It serves no purpose. The open parenthesis will always be a
> stand-alone token. Removing the ## results in the exact same code
> after substitution.

In fact, (##n is an error, as it results in an illegal token (e.g. "(1" ). This only works because it is offset by a (well-known, long-standing) bug in MSVC compiler, whereby it combines the stream of tokens after macro substitution into a string and passes it back through the lexer, which reparses it into a new, possibly different, stream of tokens.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: C++ Redistributables
Next: Force loading of DLL