I know this can be done 
Author Message
 I know this can be done

: Let's say I have a function F1, that take 2 parameters
: This function is called from everywhere within
: a controlled project.

: int F1( int X, int Y);

: Now lets say that I need to add a third parameter
: that will contain the value 0 (zero) for all the
: existing function calls, and 1 (one) for new function calls.

: I know that I can  write a macro to re-define the exsisting
: funcntion, and add the new third parameter as follows:

: #define F1(X, Y) NewF1(X, Y, 0)

: New function calls, of course,  would be coded as a call to:

: NewF1(X, Y, 1);

: The problem lies in the fact that the function F1 is prototyped
: everywhere it is about to be used:

: int X, Y, Z;
: int F1();

: Z = F1(X, Y);

: The problem lies in that the Pre-Processor maps
: the "int F1();"  to "int NewF1(,,0);"

: So that the output of the preprocessor is as follows:
: int X, Y, Z;
: int NewF1(,,0);

: Z = F1(X, Y, 0);

: I thought the macro preprocessor would only redefine
: the instances of F1 with 2 parameters,
: and not F1 with no parameters?

: What am I doing wrong?

Overestimating the intelligence of the pre-processor; it's just
not that cunning.  It look as if you are mixing K&R and ANSI
code, too.  I'd be inclined to write a sed script to update all
the files to something the preprocessor can handle; or simply
write a real function NewF1 as a wrapper for F1, which calls F1
with two arguments or verynewF1 with three arguments as required.

Will



Wed, 01 Aug 2001 03:00:00 GMT  
 I know this can be done
: Let's say I have a function F1, that take 2 parameters
: This function is called from everywhere within
: a controlled project.

: int F1( int X, int Y);

: Now lets say that I need to add a third parameter
: that will contain the value 0 (zero) for all the
: existing function calls, and 1 (one) for new function calls.

My guess is that the new F1 function acts only slightly different when
the new third parameter is 1, and you don't want to duplicate code ?

I would rename the _definition_ of F1 (only one occurrance) to newF1.
Then add the parameter to newF1 and modify the code a bit.  Make a wrapper
under the old name F1, with (old style) 2 parameters like

int F1(int X, int Y)
{
        return newF1(X, Y, 0);

Quote:
}

This way you need to modify the old code in one place only.  The old code
that calls F1 will never know the difference.  New code should call newF1
directly.

--
Frans E. van Dorsselaer



Wed, 01 Aug 2001 03:00:00 GMT  
 I know this can be done

: > The problem lies in the fact that the function F1 is prototyped
: > everywhere it is about to be used:
: >
: > int F1();

: It's possible to have functions with default parameters in C++ although
: I don't know if would work in C (probably not; corrections are welcome).
: To use them one would declare a function like so:

: int F1 (int X, int Y, int Z = 1);

You're `solution' doesn't work.  Pachiano specifically mentions the
declarations above (which BTW are not prototypes, as he claims).
You're solution requires C++, but C++ doesn't allow declarations without
the parameter list.  Remember that he posted to comp.lang.c, and his code
is definately C.

--
Frans E. van Dorsselaer



Wed, 01 Aug 2001 03:00:00 GMT  
 I know this can be done

Quote:



> : > The problem lies in the fact that the function F1 is prototyped
> : > everywhere it is about to be used:
> : >
> : > int F1();

> : It's possible to have functions with default parameters in C++ although
> : I don't know if would work in C (probably not; corrections are welcome).
> : To use them one would declare a function like so:

> : int F1 (int X, int Y, int Z = 1);

> You're `solution' doesn't work.  Pachiano specifically mentions the
> declarations above (which BTW are not prototypes, as he claims).
> You're solution requires C++, but C++ doesn't allow declarations without
> the parameter list.  Remember that he posted to comp.lang.c, and his code
> is definately C.

> --
> Frans E. van Dorsselaer


Fair enough. I'm quite happy to be correct.
--
Marcus Houlden   ICQ: 29654055
http://www.deathsdoor.com/flimflam
PGP Key ID: 0x1A1C2EA3
Fingerprint: A784 D8E5 D7AC 012F 602A  2685 F6C9 D602 1A1C 2EA3


Fri, 03 Aug 2001 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. System.Threading.Timer , am I doing this correctly ?

2. Wot am I doing rong??

3. Am I doing this right?

4. what am i doing wrong?

5. what am I doing wrong here?

6. What am I doing wrong?

7. What am I doing wrong?

8. WHAT AM I DOING WRONG?

9. what am i doing wrong!

10. What am I doing wrong (part 2)

11. What am i doing wrong?

12. What am i doing wrong in this code?

 

 
Powered by phpBB® Forum Software