Discuss C++ to C translation in the C Programming forum on Dev Shed. C++ to C translation C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.
Posts: 289
Time spent in forums: 1 Day 5 h 38 m 43 sec
Reputation Power: 14
C++ to C translation
Hi,
I've got a C++ file with a function I want to use - whatconstel (pp, epoch).
I've tryied to call it from my main program and compile - but it gives «hundreds of errors». First, I don't know how to declare it; secondo how to call it; third, how to translate it.
The code is this:
#include "precess.c";
/*precess - this routine is already made and functioning*/
#include <stdio.h>
#if __STDC__
static int islow (char *);
static int isup (char *);
static int isnumber (char *);
static int skipwh(char *);
double sqrt (double);
double sin (double);
double cos (double);
double atan2 (double, double);
double asin (double);
int precess (double *, double, int);
#else
static int islow(), isup(), isnumber(), skipwh();
double sqrt(), sin(), cos(), atan2(), asin();
int precess();
#endif
char *
whatconstel (pp, epoch)
double pp[];
double epoch;
{
int i, k;
double ra, dec, d;
double p[3];
for (i = 0; i < 3; i++)
p[i] = pp[i];
precess (p, epoch, 1);
precess (p, 2405889.25855, -1);
d = p[0] * p[0] + p[1] * p[1] + p[2] * p[2];
d = sqrt (d);
ra = atan2 (p[1], p[0]) * (RTD * 3600. / 15.);
if (ra < 0.0)
ra += 86400.0;
dec = asin (p[2] / d) * (RTD * 3600.);
for (i = 0; i < NBNDRIES; i++)
{
k = i << 2;
if (ra >= bndries[k] && ra < bndries[k+1] && dec > bndries[k+2])
{
k = (int) bndries[k+3];
return (constel[k]);
}
}
return ("?? constellation not found");
}
#if 0
/* Test program */
double J2000 = 2451545.0;
double STR = 4.8481368110953599359e-6;
test (r,d)
double r, d;
{
double c, p[3], jd;
d /= RTD;
r *= 15.0/RTD;
c = cos(d);
p[2] = sin(d);
p[0] = c * cos(r);
p[1] = c * sin(r);
jd = 2433282.423; /* 1950.0 Besselian epoch */
printf ("%8.4f %9.4f %s\n", r, d, whatconstel (p, jd));
}
int
main()
{
/* The following is an example of the output of the program:
RA = 9.0000 DEC = 65.0000 IS IN CONSTELLATION UMa
RA = 23.5000 DEC = -20.0000 IS IN CONSTELLATION Aqr
RA = 5.1200 DEC = 9.1200 IS IN CONSTELLATION Ori
RA = 9.4555 DEC = -19.9000 IS IN CONSTELLATION Hya
RA = 12.8888 DEC = 22.0000 IS IN CONSTELLATION Com
RA = 15.6687 DEC = -12.1234 IS IN CONSTELLATION Lib
RA = 19.0000 DEC = -40.0000 IS IN CONSTELLATION CrA
RA = 6.2222 DEC = -81.1234 IS IN CONSTELLATION Men */
test (9.0, 65.0);
test (23.5, -20.0);
test (5.12, 9.12);
test (9.4555, -19.9);
test (12.8888, 22.0);
test (15.6687, -12.1234);
test (19.0, -40.0);
test (6.2222, -81.1234);
exit(0);
}
#endif
Can someone help me translate the little differences that might exist, and tell me how to use this file in my main program?
Location: Central New York. Texan via Arizona, out of his element!
Posts: 8,473
Time spent in forums: 4 Weeks 6 h 48 m 41 sec
Warnings Level: 20
Number of bans: 3
Reputation Power: 3242
Please read the post for new users and put code tags around your code to preserve the indentation. It's right at the top of the forum, says READ THIS FIRST.
__________________
Functionality rules and clarity matters; if you can work a little elegance in there, you're stylin'.
If you can't spell "u", "ur", and "ne1", why would I hire you? 300 baud modem? Forget I mentioned it. DaWei on PointersPolitically Incorrect.
Posts: 1,200
Time spent in forums: 1 Week 1 Day 11 h 47 m 52 sec
Reputation Power: 11
what let you believe it's a c++ progr ?
i find, it's a very worst writted (K&R style, NOT ansi)
essay for a 'c' code.
i did not study it, scanning it i saw errors, globals ...
sure it does not run.
i will&&can not believe, about 40 years after K&R,
that's the level of modern 'c' (+= other) programmers.