ok here's what i have done;
#define a(r) ((4)*(1/r)*(1-(1/r)));
using it like this:
tot = tot + a(r);
But while compiling i get :
invalid operands to binary +
Can anyone suggest me what am i doing wrong?
Printable View
ok here's what i have done;
#define a(r) ((4)*(1/r)*(1-(1/r)));
using it like this:
tot = tot + a(r);
But while compiling i get :
invalid operands to binary +
Can anyone suggest me what am i doing wrong?
You've got an error that doesn't cause an error (here): this line now ends in two semicolons (one from the #define, one from the line itself).
What is r, then? I hope it's a floating-point thing, otherwise 1/r could get tricky.
And why not use a function instead of a pseudofunction?
r is double and i mistype it i don't have ";" in my real code and 4 is 4.0 and 1 is 1.0 is my code. I am just trying to this pseudofunction .
r is double and i mistype it i don't have ";" in my real code and 4 is 4.0 and 1 is 1.0 is my code. I am just trying to this pseudofunction .
#define a(r) (-4.0)*(1.0/(r))*((1.0/(r))-1.0)
And there is subroutine
which uses this function
tot = tot + a(r);
Minimum sample
Compiles fine.Code:#define a(r) (-4.0)*(1.0/(r))*((1.0/(r))-1.0)
int main(void)
{
double tot = 0;
double r = 10;
tot = tot + a(r);
return 0;
}
Are you sure there are not problems on previous lines? Are you sure the compiler error is referring to this line? Are you sure your types are OK, e.g tot is not char* or whatever?
I have also called the same function in main and it's works fine but when i tired to call it in a subroutine it didn't work at all
And remember, the file is parsed from top to bottom, so attempting to call a macro above where it is defined simply won't work.
@tabstop: how to do it then?
Define it before you use it. (This seems a bit too obvious, but is correct nevertheless.)
ok the basic structure is :
Code:#define ......
int main()
{
}
bool func() /**bool is taken care of and works fine**/
{
defined function is called here as explained above
}
@tabstop :defined it but it didn't work