*
:
>
> Could anyone solve the problem for the code below
"The" problem? I count a multitude of problems. Which one?
> The Code:
>
> #include "stdio.h"
Use the <headername> form instead of "headername" for standard headers.
That way you avoid picking up a header with the same name in a local
directory.
> #include "iostream.h"
This is not a standard header, and won't compile with e.g. Visual C++
7.1 or better. Use <iostream> instead. <iostream> is a standard header.
> void Temp( int a, char* str,...)
The second argument should be declared as
char const* str
unless you want the function Temp to be able to modify the contents of
'str'.
The ellipsis '...' should generally not be used in C++ code, because
it's /dangerous/ (not typesafe) and /limited/ (no non-POD objects);
there are much better typesafe solutions.
> {
> //code to handle the arguments
> }
>
> #define MYPRINT(_x_) printf _x_
> #define MYPRINT1(_x_) Temp( 10,_x_)
Generally it's not a good idea to use macros. See this group's FAQ and
Bjarne Stroustrup's C++ FAQ for reasons why.
> int main()
> {
> MYPRINT(("This is a test for multiple argument %s
> %d",__FILE__,__LINE__));
> MYPRINT1(("This is a test for multiple argument %s
> %d",__FILE__,__LINE__));
>
> return 0;
> }
>
> Problem:
>
> In the first macro I am able to get the result as expected from the
> printf where as in the second case my parameters are not properly
> passed to the function Temp. Could anyone of you tell me why i am not
> abel to use the macro to pass parameter to a function with some
> mandatory number of parameter and variable number of parameter?
The second macro invocation does not work because it expands to
Temp( 10, ("some text",__FILE__,__LINE__));
which is syntactically invalid.
> Is there any way that i can paa the parameter as i expected?how?
No, not as you expected.
A solution depends on what you want to achieve. Obviously it's not
what's illustrated by your code, because that could be much more easily
achieved by calling Temp directly without the macro. In other words,
you have illustrated a flawed solution to some problem, instead of the
problem itself -- to get help with that problem, explain it.
I suspect, though, that it has to do with logging or tracing?
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?