when I compiling this program it gives me this error
//////////////////////////////////////////////////
////////////////////////////////////////////////
In function 'double inflexion(double*)':
27:1: warning: control reaches end of non-void function [-Wreturn-type]
In function 'int ninflexion(double*)':
37:1: warning: control reaches end of non-void function [-Wreturn-type]
In function 'int main(int, char**)':
69:15: warning: iteration 49u invokes undefined behavior [-Waggressive-loop-optimizations]
68:3: note: containing loop
60:39: warning: iteration 49u invokes undefined behavior [-Waggressive-loop-optimizations]
57:4: note: containing loop
/////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
and I don't know how to solve it please someone who can find me where is the problem .
a typed function must return a value.
int foo()
{
if(1==2)
return 3; //this does not happen if 1 does not equal 2.
///nothing is returned: the return was skipped.
//control (the place in the program where it was executing)
//has reached the end (here) of a non void function (its type int) without return.
}
the infinity (?) loops over i appear to go out of range in the array bounds. This is undefined.
you also take the undefined index via uninitialized variables.
In function 'double inflexion(double*)':
27:1: warning: control reaches end of non-void function [-Wreturn-type]
Unless a particular condition (which isn't correct BTW) is met, the routine inflexion will not return a value. But it promised to return a double, didn't it: double inflexion(double x[])
In function 'int ninflexion(double*)':
37:1: warning: control reaches end of non-void function [-Wreturn-type]
You declared arrays t[], xv[] and yv[] with one too few elements for the loops that initialise them:
1 2 3
double t[n-1];
double xv[n-1];
double yv[n-1];
These should be declared with length n, not n-1.
Your compiler didn't pick it up, but the following two lines are (currently) illegal in standard c++ because the array size isn't known at run time:
1 2
xinf=xv[infn];
yinf=yv[infn];
As @FurryGuy says, please use code tags so that it preserves indentation and we can read your code easily. It would also be useful to state what your code is supposed to do. As far as I can tell it's working out the parametric coordinates of some space curve - but who knows.
@lastchance (5669)
thank you, my dear friend.
with this c++ code, I want to simulate a bow-tie filter exactly the filter thickness at each angle theta of the ray coming from the source [computed tomography].
with this c++ code, I want to simulate a bow-tie filter exactly the filter thickness at each angle theta of the ray coming from the source [computed tomography].
OK, your expression for t[] is equation (19) in that reference. Where are your expressions for xv[] and yv[] in the paper? Also, Table 1 in the paper gives c2 as 6.0 (for aluminimum) rather than 7.5.
If your routine inflection() is supposed to return a point of inflection then it won't (looks more like a turning point/stationary point). Not sure what you are trying to do here.
This also runs and produces some output to file.
I've made some changes to make it clear (to me at least) wtf goes on with constants vs variables but this does not mean the program does what it you meant it to do.
The journal(s) seem to be tackling a more complex problem, even involving Monte Carlo methods. maybe that's why you included time/math/rand but didn't use them?
You could make a lot of use of ordinary coding conventions with meaningful variable names and adopting the principles of self-documenting code along with selective but effective commenting. Single letter variable names, to put it bluntly, is bad practice and essentially crap.
The constant LIMIT could possibly introduce an off-by-one-error with what I have done? I have not checked.