portability of simple struct vs. array?

Brian Donahue bridon at attc.UUCP
Sat Feb 16 05:17:45 AEST 1991


In article <1058 at attc.UUCP> i wrote:
>Stupid question.  (maybe should go into FAQ?)
>i have a function that's declared as:
>
>foo( arg )
>double arg[3];
>{
>...
>and, outside of this function i have a struct like:
>typedef struct {
>	double xyz[3];
>   } point;
>Q1:  can i call foo() with a pointer to a point struct? 

Yeah. a follow-up to my own question (good, huh?)
I over-simplified the original question and people replied
why dont you just call foo with p.xyz ?? Yeah, i hear ya.

Actually, the situation is more like: foo is declared as:
foo( arg )
double arg[6][3];
{
...

and i have an array of structs of:
typedef struct {
	double xyz[3];
	double tangent[3];
   } point_tan;

Rephrasing my questions:
Q1:  can i call foo() with a pointer to a point_tan struct? 
     eg. foo( &pttan[i] ) 
Q2:  can i do so portably? or am i making too much of an assumption
     by assuming contiguous, non-padded structures?
Q3:  Is there some documentation in K&R that supports your answer?


Because of the stupidity of this question, plz reply via email
to:

	bridon at auto-trol.COM

thanks again!



More information about the Comp.lang.c mailing list