struct
{
float lat_radians; //latitude in radians
float lon_radians; //longtiude in radians
float alt_radians; //altiude in radians
double ECEF_X; // ECEF X in metres
double ECEF_Y; // ECEF Y in metres
double ECEF_Z; // ECEF Z in metres
} gps_position;
void main()
{
LatLongAlt_to_ECEF_coordinates(struct gps_position {float lon; float lat; float alt} arg);
}
i having error from c141: syntax error near 'struct'. i have tried to figure but could not find any solution
Please help .. thanksBest regards kevin
thanks for your useful information. But i did some changes to my codes and i still having problems of error C3861: 'lla_to_ECEF': identifier not found & error C2365: 'lla_to_ECEF' : redefinition; prev开发者_StackOverflowious definition was 'formerly unknown identifier' May i know how can i correct my mistake from here? thanks kevin
#include <stdio.h>
struct gps_position
{
float alt;
float lon;
float lat;
double ECEF_x;
};
void main ()
{
lla_to_ECEF (gps_position.alt);
return;
}
float lla_to_ECEF (float alt)
{
//some calculate to be done
}
You need to bring the declaration right after struct. See you favourite C Book for examples.
struct gps_position
{
float lat_radians; //latitude in radians
float lon_radians; //longtiude in radians
float alt_radians; //altiude in radians
double ECEF_X; // ECEF X in metres
double ECEF_Y; // ECEF Y in metres
double ECEF_Z; // ECEF Z in metres
} ;
or
typedef struct
{
float lat_radians; //latitude in radians
float lon_radians; //longtiude in radians
float alt_radians; //altiude in radians
double ECEF_X; // ECEF X in metres
double ECEF_Y; // ECEF Y in metres
double ECEF_Z; // ECEF Z in metres
} gps_position ;
First off, that is not a valid way of declaring a struct try this:
struct gps_position
{
float lat_radians; //latitude in radians
float lon_radians; //longtiude in radians
float alt_radians; //altiude in radians
double ECEF_X; // ECEF X in metres
double ECEF_Y; // ECEF Y in metres
double ECEF_Z; // ECEF Z in metres
};
Second, if you want to pass a struct to a function do:
gps_position arg;
//Do assigning stuff before the function is called.
LatLongAlt_to_ECEF_coordinates(arg);
You want to start by giving a tag to your gps_position struct:
struct gps_position
{
float lat_radians; //latitude in radians
float lon_radians; //longtiude in radians
float alt_radians; //altiude in radians
double ECEF_X; // ECEF X in metres
double ECEF_Y; // ECEF Y in metres
double ECEF_Z; // ECEF Z in metres
};
What you had before defined a variable named gps_position
, but didn't give a name to the struct itself.
void main()
Not that it's particularly relevant to the question at hand, but main
should normally return an int
.
{
LatLongAlt_to_ECEF_coordinates(struct gps_position {float lon; float lat; float alt} arg);
}
If you want to call a function with a gps_position
, you'd normally do something like this:
struct gps_position pos;
LatLongAlt_to_ECEF_coordinates(pos);
Only in a typical case, you want to pass a pointer to the struct:
LatLongAlt_to_ECEF_coordinates(&pos);
Personally, I think I'd separate the radian-based coordinates from the ECEF-based coordinates:
struct radian_coords {
float latitude, longitude, altitude;
}
struct ECEF_coords {
double X, Y, Z;
}
Then when you convert from one to another, you'd pass an instance of each:
struct radian_cords r_pos = { 12345.6, 23456.7, 123.4 };
struct ECEF_coords e_pos;
LatLongAlt_to_ECEF_coordinates(&r_pos, &e_pos);
Or, you could write the function to return the correct type:
e_pos = LatLongAlt_to_ECEF_coordinates(&r_pos);
In this case, your function header would look something like:
struct e_pos LatLongAlt_to_ECEF_coordinates(struct r_pos const *input) {
struct e_pos ret;
// compute and assign values to ret.X, ret.Y and ret.Z
return ret;
}
This will eradicate your error:
This is the right way to pass structure as arguments into function
#include <stdio.h>
typedef struct
{
float lat_radians; //latitude in radians
float lon_radians; //longtiude in radians
float alt_radians; //altiude in radians
double ECEF_X; // ECEF X in metres
double ECEF_Y; // ECEF Y in metres
double ECEF_Z; // ECEF Z in metres
} gps_position;
void main()
{
gps_position gps;
LatLongAlt_to_ECEF_coordinates(gps);
}
精彩评论