Hi I am trying to run this C code in Visual Studio along with a set of Cpp files.
It gives the below errors
error 2143 : syntax error : missing ')' before '&'
error 2143 : syntax error : missing '{' before '&'
error 2059 : syntax error : '&'
error 2059 : syntax error : ')'

and the error is at
<< void polar_to_cartesian(float azimuth, float length, float altitude, float&x1, float&y1, float&z1) >>

I am not sure why this is popping up as all my declarations are correct .
Please help me in resolving this

#include <math.h>

void polar_to_cartesian(float azimuth, float length, float altitude, float&x1, float&y1, float&z1)
{

	// do x-z calculation 

	float theta    = (90 - azimuth) * 0.017453278;
	float tantheta = (float) tan (theta);

	x1 = (float) sqrt ( (length * length) / (tantheta * tantheta + 1));
	z1 = tantheta * x1;

	x1 = -x1;

	if (((azimuth >= 180.0) && (azimuth <= 360.0)) || (azimuth == 0.0f)){
		x1 = -x1;
		z1 = -z1;
	}

	float radian_alt = altitude * 0.017453278;
	

	//	 calculate y, and adjust x and z
	y1 = (float) (sqrt (z1*z1 + x1*x1) * sin (radian_alt));

	if (length < 0) {
		x1 = -x1;
		z1 = -z1;
		y1 = -y1;
	}
	float cospsi = (float) cos (radian_alt);
	x1 = x1 * cospsi;
	z1 = z1 * cospsi;

	
}


/* Rotates (rx,ry,rz) point about the (ax,ay,az) axis 'angle' radians,
   'borrowed' from Mesa (the OpenGL replacement [url]www.mesa3d.org[/url] */
void rotation( double angle, double ax, double ay, double az,
                         double *rx, double *ry, double *rz)
{
   double mag, s, c;
   double x,y,z,xx, yy, zz, xy, yz, zx, xs, ys, zs, one_c;

   s = sin(angle);
   c = cos(angle);

  // mag = DISTANCE(ax,ay,az);
   mag = sqrt((ax)*(ax)+(ay)*(ay)+(az)*(az));

   if (mag == 0.0) return;

   x = ax/mag;
   y = ay/mag;
   z = az/mag;

   xx = x * x;
   yy = y * y;
   zz = z * z;
   xy = x * y;
   yz = y * z;
   zx = z * x;
   xs = x * s;
   ys = y * s;
   zs = z * s;
   one_c = 1.0 - c;

   x = *rx*((one_c * xx) + c);
   y = *rx*((one_c * xy) - zs);
   z = *rx*((one_c * zx) + ys);

   x += *ry*((one_c * xy) + zs);
   y += *ry*((one_c * yy) + c);
   z += *ry*((one_c * yz) - xs);

   x += *rz*((one_c * zx) - ys);
   y += *rz*((one_c * yz) + xs);
   z += *rz*((one_c * zz) + c);
   
   *rx=x; *ry=y; *rz=z;
}

Thanks in advance

Hi I am trying to run this C code in Visual Studio along with a set of Cpp files.
It gives the below errors
error 2143 : syntax error : missing ')' before '&'
error 2143 : syntax error : missing '{' before '&'
error 2059 : syntax error : '&'
error 2059 : syntax error : ')'

and the error is at
<< void polar_to_cartesian(float azimuth, float length, float altitude, float&x1, float&y1, float&z1) >>

I am not sure why this is popping up as all my declarations are correct .
Please help me in resolving this

You're trying to compile C++ code as C, so the compiler barfs. The reference operator ( & ) only exists in C++.

You're trying to compile C++ code as C, so the compiler barfs. The reference operator ( & ) only exists in C++.

Thanks for the reply .
Do we have any reference operators in C that I can replace with ?

Thanks for the reply .
Do we have any reference operators in C that I can replace with ?

C doesn't have the reference operator at all. You can change the three output parameters to pointers, much like the rotation function does. For example: float* x1 . You'll also have to update the body of the function to dereference these parameters when you want to use their values: *z1 = tantheta * *x1; . Then any code that calls the function needs to explicitly take the reference of the output parameters as well: polar_to_cartesian(azimuth, length, altitude, x1, y1, z1) becomes polar_to_cartesian(azimuth, length, altitude, &x1, &y1, &z1) .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.