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?
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 .
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
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 .
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
#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?
Last edited by anon; 06-01-2009 at 04:50 PM.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
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
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
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