Path: utzoo!attcan!uunet!dptechno!dptechno.uucp From: dave@dptechno.uucp (Dave Lee) Newsgroups: comp.lang.c Subject: Cast struct * --> double * --> struct * Portable ? Message-ID: <588@dptechno.UUCP> Date: 11 Oct 90 22:20:16 GMT Sender: dave@dptechno.UUCP Organization: D.P. Technology Corp. Camarillo California Lines: 54 Assuming the following : struct somestruct { /*** data */ } ; f_s( s ) struct somestruct *s; { /* do something with s */ } f_d( d , special ) double *d; int special; { if( special ) f_s( (struct somestruct *) d ); else /* Something with a double * */ } Will the following call be generally portable ? struct somestruct THIS_ONE; f_d( (double *) &THIS_ONE , 1 ); Restated: is the following series of casts portable ? struct * --> double * --> struct * Does this require that the structure be alligned on a sizeof(double) boundry ? Would placing a double as the first member of the structure guarentee such allignment ? I Believe that if the structure were allocated with malloc() that the resulting pointer would be worst case alligned and therefore will not suffer from allignment problems. How about static or auto structs ? I understand that this is not good programming, but there exists a large number of routines in a program that are already coded to expect a double * and I would prefer not to have to duplicate all that code just to add this special case. I suspect that this is not truely portable, but are there any "likely" problems with this? Is there some kludge I should do to make this work, like placing a double as the first member of somestruct ? Please Email or Post as convient. -- Dave Lee uunet!dptechno!dave