Elementary question on preprocessors and xlw

P

pauldepstein

I am using the xlw package as a c++ wrapper for excel functions. In
our c++ library, there is an excel function which our c++ developers
refer to as DevelopersFunction, and which the excel users refer to as
ExcelFunction. [Names of functions changed to preserve corporate
confidentiality]

There is some code containing the string "DevelopersFunction" which
results in the excel users seeing the text DevelopersFunction when
they use the insert_function command in excel.

But the excel users should see "ExcelFunction"

I would imagine that this can be done by a simple preprocessor #define
command.
I tried to rename the function to ExcelFunction in excel and then
#define DevelopersFunction ExcelFunction

But this doesn't appear to work.

Any suggestions.

Thanks,

Paul Epstein
 
C

Chris ( Val )

I am using the xlw package as a c++ wrapper for excel functions. In
our c++ library, there is an excel function which our c++ developers
refer to as DevelopersFunction, and which the excel users refer to as
ExcelFunction. [Names of functions changed to preserve corporate
confidentiality]

There is some code containing the string "DevelopersFunction" which
results in the excel users seeing the text DevelopersFunction when
they use the insert_function command in excel.

But the excel users should see "ExcelFunction"

I would imagine that this can be done by a simple preprocessor #define
command.
I tried to rename the function to ExcelFunction in excel and then
#define DevelopersFunction ExcelFunction

But this doesn't appear to work.

Any suggestions.

To be honest, I can't follow your description of
the problem, and I don't know of any "packages"
(at least not in a the C++ context).

Maybe you can look at using a 'typedef'?

Please try to be a little more clear and someone
else might be able to help you.
 
P

pauldepstein

I am using the xlw package as a c++ wrapper for excel functions. In
our c++ library, there is an excel function which our c++ developers
refer to as DevelopersFunction, and which the excel users refer to as
ExcelFunction. [Names of functions changed to preserve corporate
confidentiality]
There is some code containing the string "DevelopersFunction" which
results in the excel users seeing the text DevelopersFunction when
they use the insert_function command in excel.
But the excel users should see "ExcelFunction"
I would imagine that this can be done by a simple preprocessor #define
command.
I tried to rename the function to ExcelFunction in excel and then
#define DevelopersFunction ExcelFunction
But this doesn't appear to work.
Any suggestions.

To be honest, I can't follow your description of
the problem, and I don't know of any "packages"
(at least not in a the C++ context).

Maybe you can look at using a 'typedef'?

Please try to be a little more clear and someone
else might be able to help you.

Thanks.

I have found a way of clarifying the problem, now that I understand
the issue better myself

I have a constructor called MyConstructor which takes a const
std::string & parameter.

I want the preprocessor to translate MyConstructor("dog") into
MyConstructor("cat").

This seems like a #define problem rather than a typedef problem.

Thanks again,

Paul Epstein
 
C

Chris ( Val )

On Oct 4, 7:45 pm, (e-mail address removed) wrote:
I am using the xlw package as a c++ wrapper for excel functions. In
our c++ library, there is an excel function which our c++ developers
refer to as DevelopersFunction, and which the excel users refer to as
ExcelFunction. [Names of functions changed to preserve corporate
confidentiality]
There is some code containing the string "DevelopersFunction" which
results in the excel users seeing the text DevelopersFunction when
they use the insert_function command in excel.
But the excel users should see "ExcelFunction"
I would imagine that this can be done by a simple preprocessor #define
command.
I tried to rename the function to ExcelFunction in excel and then
#define DevelopersFunction ExcelFunction
But this doesn't appear to work.
Any suggestions.
To be honest, I can't follow your description of
the problem, and I don't know of any "packages"
(at least not in a the C++ context).
Maybe you can look at using a 'typedef'?
Please try to be a little more clear and someone
else might be able to help you.
- Show quoted text -

Thanks.

I have found a way of clarifying the problem, now that I understand
the issue better myself

Good :)
I have a constructor called MyConstructor which takes a const
std::string & parameter.

I want the preprocessor to translate MyConstructor("dog") into
MyConstructor("cat").

This seems like a #define problem rather than a typedef problem.

Thanks again,

# include <iostream>
# include <string>

struct Foo
{
Foo( const std::string& s );
};

// Try with and without this (comment out)...
#define DevelopersFunction "DevelopersFunction"

# if defined DevelopersFunction
Foo::Foo( const std::string& s ) {
std::cout << s << " from: DevelopersFunction\n";
}
#else
Foo::Foo( const std::string& s ) {
std::cout << s << " from: ExcelFunction\n";
}
#endif


int main()
{
Foo( "arg" );

std::cin.get();
return 0;
}

Does his help?
 
G

Guest

I am using the xlw package as a c++ wrapper for excel functions. In
our c++ library, there is an excel function which our c++ developers
refer to as DevelopersFunction, and which the excel users refer to as
ExcelFunction. [Names of functions changed to preserve corporate
confidentiality]
There is some code containing the string "DevelopersFunction" which
results in the excel users seeing the text DevelopersFunction when
they use the insert_function command in excel.
But the excel users should see "ExcelFunction"
I would imagine that this can be done by a simple preprocessor #define
command.
I tried to rename the function to ExcelFunction in excel and then
#define DevelopersFunction ExcelFunction
But this doesn't appear to work.
Any suggestions.

To be honest, I can't follow your description of
the problem, and I don't know of any "packages"
(at least not in a the C++ context).

Maybe you can look at using a 'typedef'?

Please try to be a little more clear and someone
else might be able to help you.

Thanks.

I have found a way of clarifying the problem, now that I understand
the issue better myself

I have a constructor called MyConstructor which takes a const
std::string & parameter.

I want the preprocessor to translate MyConstructor("dog") into
MyConstructor("cat").

This seems like a #define problem rather than a typedef problem.

#include <iostream>
#include <string>

#ifdef NDEBUG
#define WORD "dog"
#else
#define WORD "cat"
#endif

struct Foo
{
std::string str;
Foo(const std::string& s) : str(s) { }
};


int main()
{
Foo f(WORD);
std::cout << f.str;
}

You just have do figure out something to test against instead of NDEBUG
and it should all work.
 
P

pauldepstein

On Oct 4, 7:45 pm, (e-mail address removed) wrote:
I am using the xlw package as a c++ wrapper for excel functions. In
our c++ library, there is an excel function which our c++ developers
refer to as DevelopersFunction, and which the excel users refer to as
ExcelFunction. [Names of functions changed to preserve corporate
confidentiality]
There is some code containing the string "DevelopersFunction" which
results in the excel users seeing the text DevelopersFunction when
they use the insert_function command in excel.
But the excel users should see "ExcelFunction"
I would imagine that this can be done by a simple preprocessor #define
command.
I tried to rename the function to ExcelFunction in excel and then
#define DevelopersFunction ExcelFunction
But this doesn't appear to work.
Any suggestions.
To be honest, I can't follow your description of
the problem, and I don't know of any "packages"
(at least not in a the C++ context).
Maybe you can look at using a 'typedef'?
Please try to be a little more clear and someone
else might be able to help you.

I have found a way of clarifying the problem, now that I understand
the issue better myself

Good :)
I have a constructor called MyConstructor which takes a const
std::string & parameter.
I want the preprocessor to translate MyConstructor("dog") into
MyConstructor("cat").
This seems like a #define problem rather than a typedef problem.
Thanks again,

# include <iostream>
# include <string>

struct Foo
{
Foo( const std::string& s );
};

// Try with and without this (comment out)...
#define DevelopersFunction "DevelopersFunction"

# if defined DevelopersFunction
Foo::Foo( const std::string& s ) {
std::cout << s << " from: DevelopersFunction\n";
}
#else
Foo::Foo( const std::string& s ) {
std::cout << s << " from: ExcelFunction\n";
}
#endif

int main()
{
Foo( "arg" );

std::cin.get();
return 0;
}

Does his help?

Chris,

I appreciate your attempt to help me but this seems like a poor
solution because it involves constantly changing the c++ code
depending on whether an EXCEL user or a developer is using it.

The idea is for the same piece of code to work to provide a different
function name depending on whether the source code is being looked at,
or whether the xll is being run.

Paul
 
P

pauldepstein

On Oct 4, 7:45 pm, (e-mail address removed) wrote:
I am using the xlw package as a c++ wrapper for excel functions. In
our c++ library, there is an excel function which our c++ developers
refer to as DevelopersFunction, and which the excel users refer to as
ExcelFunction. [Names of functions changed to preserve corporate
confidentiality]
There is some code containing the string "DevelopersFunction" which
results in the excel users seeing the text DevelopersFunction when
they use the insert_function command in excel.
But the excel users should see "ExcelFunction"
I would imagine that this can be done by a simple preprocessor #define
command.
I tried to rename the function to ExcelFunction in excel and then
#define DevelopersFunction ExcelFunction
But this doesn't appear to work.
Any suggestions.
To be honest, I can't follow your description of
the problem, and I don't know of any "packages"
(at least not in a the C++ context).
Maybe you can look at using a 'typedef'?
Please try to be a little more clear and someone
else might be able to help you.

I have found a way of clarifying the problem, now that I understand
the issue better myself
I have a constructor called MyConstructor which takes a const
std::string & parameter.
I want the preprocessor to translate MyConstructor("dog") into
MyConstructor("cat").
This seems like a #define problem rather than a typedef problem.

#include <iostream>
#include <string>

#ifdef NDEBUG
#define WORD "dog"
#else
#define WORD "cat"
#endif

struct Foo
{
std::string str;
Foo(const std::string& s) : str(s) { }

};

int main()
{
Foo f(WORD);
std::cout << f.str;

}

You just have do figure out something to test against instead of NDEBUG
and it should all work.

Thanks a lot, Erik

I believe I can implement this idea!

Paul Epstein
 
C

Chris ( Val )

[snip]

I appreciate your attempt to help me but this seems like a poor
solution because it involves constantly changing the c++ code
depending on whether an EXCEL user or a developer is using it.

The idea is for the same piece of code to work to provide a different
function name depending on whether the source code is being looked at,
or whether the xll is being run.

It's not a difficult problem to solve at all, and in fact
it was very simple what Erik provided you with.

The problem for me as I outlined from the beginning, is
that I really didn't understand your requirements, so
just tried to provide an idea.

Anyway, glad you got what you were looking for :)
 
P

pauldepstein

[snip]

I appreciate your attempt to help me but this seems like a poor
solution because it involves constantly changing the c++ code
depending on whether an EXCEL user or a developer is using it.
The idea is for the same piece of code to work to provide a different
function name depending on whether the source code is being looked at,
or whether the xll is being run.

It's not a difficult problem to solve at all, and in fact
it was very simple what Erik provided you with.

The problem for me as I outlined from the beginning, is
that I really didn't understand your requirements, so
just tried to provide an idea.

Anyway, glad you got what you were looking for :)

Chris,

Everything you say is correct.

1) The problem was simple -- I never claimed to be an expert.

2) I didn't explain the problem clearly at the beginning.

3) Erik provided a simple solution.

However, I did make an additional point which is of some value, and I
stand by it:

4) This snippet of code of yours is _bad practice_ no matter what
problem you thought I had.

Beginning of quote

// Try with and without this (comment out)...
#define DevelopersFunction "DevelopersFunction"

End of quote.

It is simply bad style to use commenting out in this way.


So it does seem appropriate, in a coding forum for me to point out
that this is bad, and explain why, particularly since I thanked you
for your help at the beginning.

Paul Epstein
 
C

Chris ( Val )

On Oct 5, 12:19 am, (e-mail address removed) wrote:
I appreciate your attempt to help me but this seems like a poor
solution because it involves constantly changing the c++ code
depending on whether an EXCEL user or a developer is using it.
The idea is for the same piece of code to work to provide a different
function name depending on whether the source code is being looked at,
or whether the xll is being run.
It's not a difficult problem to solve at all, and in fact
it was very simple what Erik provided you with.
The problem for me as I outlined from the beginning, is
that I really didn't understand your requirements, so
just tried to provide an idea.
Anyway, glad you got what you were looking for :)


Paul,

Everything you say is correct.

1) The problem was simple -- I never claimed to be an expert.

Correct, and I never claimed otherwise.
2) I didn't explain the problem clearly at the beginning.
Correct.

3) Erik provided a simple solution.
Correct.

However, I did make an additional point which is of some value, and I
stand by it:

Yes, *some* value, which allowed me to present you
with *an idea*.
4) This snippet of code of yours is _bad practice_ no matter what
problem you thought I had.

You can call it what you like. It was an idea, that's
all and nothing more to it. I didn't expect you to
implement exactly what I provided, that is your job
because you are the domain expert and in complete
understanding of your problem.

I explained that I still did not fully understand your
requirements, and my sole intention was to put forward
*an idea* for you to work with.
Beginning of quote

// Try with and without this (comment out)...
#define DevelopersFunction "DevelopersFunction"

End of quote.

It is simply bad style to use commenting out in this way.

When trying to show someone how to use *an idea* they
have put forward, and to see the side effects of using
it, the most experienced of us do it all the time.
So it does seem appropriate, in a coding forum for me to point out
that this is bad, and explain why, particularly since I thanked you
for your help at the beginning.

I think you have missunderstood the whole point of my
example and reply.

I appreciate you thanking me for the help, and that's
all I tried to do. However, you have to understand that
people give their time in helping others here for
free, and often present *ideas*, and not necessarily
*complete solutions* - After all, this is not a help
desk.

I did not abuse you, try to belittle you, nor make
any claims that the example code I provided was the
right solution for you.

Please take these facts into consideration when
responding to people who are trying to help you
in the future.
 
P

pauldepstein

Chris ( Val ) said:
I did not abuse you, try to belittle you, nor make
any claims that the example code I provided was the
right solution for you.

Please take these facts into consideration when
responding to people who are trying to help you
in the future.

No, you did not abuse me, but I certainly _did_ think that you were
trying to belittle me -- that's how I understood your repeated
assertions
about how simple the problem was. I thought that your purpose was to
belittle me
because I couldn't see another reason for you to stress the fact that
the problem is simple.

I am happy to accept that that was not your intention however.

Paul Epstein
 
C

Chris ( Val )

No, you did not abuse me, but I certainly _did_ think that you were
trying to belittle me -- that's how I understood your repeated
assertions
about how simple the problem was. I thought that your purpose was to
belittle me
because I couldn't see another reason for you to stress the fact that
the problem is simple.

No, it was not my intention to belittle you in any way shape
or form.
I am happy to accept that that was not your intention however.

Glad to hear :)

Cheers,
Chris Val
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top