By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,042 Members | 1,017 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,042 IT Pros & Developers. It's quick & easy.

Elementary question on preprocessors and xlw

P: n/a
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

Oct 4 '07 #1
Share this Question
Share on Google+
11 Replies


P: n/a
On Oct 4, 7:45 pm, pauldepst...@att.net 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.

--
Chris Val



Oct 4 '07 #2

P: n/a
On Oct 4, 7:05 pm, "Chris ( Val )" <chris...@gmail.comwrote:
On Oct 4, 7:45 pm, pauldepst...@att.net 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.

--
Chris Val- Hide quoted text -

- Show quoted text -
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

Oct 4 '07 #3

P: n/a
On Oct 4, 9:23 pm, pauldepst...@att.net wrote:
On Oct 4, 7:05 pm, "Chris ( Val )" <chris...@gmail.comwrote:


On Oct 4, 7:45 pm, pauldepst...@att.net 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.
--
Chris Val- Hide quoted text -
- 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?

--
Chris val

Oct 4 '07 #4

P: n/a
On 2007-10-04 13:23, pa**********@att.net wrote:
On Oct 4, 7:05 pm, "Chris ( Val )" <chris...@gmail.comwrote:
>On Oct 4, 7:45 pm, pauldepst...@att.net 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.

--
Chris Val- Hide quoted text -

- Show quoted text -

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.

--
Erik Wikström
Oct 4 '07 #5

P: n/a
On Oct 4, 7:41 pm, "Chris ( Val )" <chris...@gmail.comwrote:
On Oct 4, 9:23 pm, pauldepst...@att.net wrote:


On Oct 4, 7:05 pm, "Chris ( Val )" <chris...@gmail.comwrote:
On Oct 4, 7:45 pm, pauldepst...@att.net 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.
--
Chris Val- Hide quoted text -
- 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?

--
Chris val- Hide quoted text -

- Show quoted text -
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

Oct 4 '07 #6

P: n/a
On Oct 4, 7:54 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-10-04 13:23, pauldepst...@att.net wrote:


On Oct 4, 7:05 pm, "Chris ( Val )" <chris...@gmail.comwrote:
On Oct 4, 7:45 pm, pauldepst...@att.net 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.
--
Chris Val- Hide quoted text -
- Show quoted text -
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.

--
Erik Wikström- Hide quoted text -

- Show quoted text -
Thanks a lot, Erik

I believe I can implement this idea!

Paul Epstein

Oct 4 '07 #7

P: n/a
On Oct 5, 12:19 am, pauldepst...@att.net wrote:
On Oct 4, 7:41 pm, "Chris ( Val )" <chris...@gmail.comwrote:
[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 Val


Oct 4 '07 #8

P: n/a
On Oct 4, 10:50 pm, "Chris ( Val )" <chris...@gmail.comwrote:
On Oct 5, 12:19 am, pauldepst...@att.net wrote:
On Oct 4, 7:41 pm, "Chris ( Val )" <chris...@gmail.comwrote:

[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 Val
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


Oct 5 '07 #9

P: n/a
On Oct 5, 10:30 am, pauldepst...@att.net wrote:
On Oct 4, 10:50 pm, "Chris ( Val )" <chris...@gmail.comwrote:


On Oct 5, 12:19 am, pauldepst...@att.net wrote:
On Oct 4, 7:41 pm, "Chris ( Val )" <chris...@gmail.comwrote:
[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 Val

Chris,

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.

--
Chris Val
Oct 5 '07 #10

P: n/a
"Chris ( Val )" <chris...@gmail.comwrote:
>
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.

--
Chris Val- Hide quoted text -
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
Oct 5 '07 #11

P: n/a
On Oct 6, 12:40 am, pauldepst...@att.net wrote:
"Chris ( Val )" <chris...@gmail.comwrote:
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.
--
Chris Val- Hide quoted text -

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

Oct 6 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.