#include /* The union guarantees that the structs are aligned, in C99. * * In C90, standard does not discuss the issue, but all * compilers known to man align them anyway. The C99 * guarantee seems to be an attempt to standardize * that behaviour. * * The union type is never actually used, unless somebody * can think of a reason to use it... */ union gsl_vector_union_t { struct gsl_vector_struct_t { double * data; size_t size; int stride; } as_vector; struct gsl_const_vector_struct_t { const double * data; size_t size; int stride; } as_const_vector; }; typedef struct gsl_vector_struct_t gsl_vector; typedef struct gsl_const_vector_struct_t gsl_const_vector; void gsl_some_typical_function(const gsl_vector * v) { /* do something which might twiddle v.data[] */ } void gsl_some_typical_const_function(const gsl_const_vector * v) { /* do something which does not twiddle v.data[] */ } int main() { gsl_vector v; gsl_const_vector cv; /* might be twiddling v.data[] */ gsl_some_typical_function(&v); /* claims not to twiddle cv.data[] */ gsl_some_typical_const_function(&cv); /* claims not to twiddle v.data[] */ gsl_some_typical_const_function((const gsl_const_vector *) &v); /* a misuse; but this sort of thing can never be prevented anyway */ gsl_some_typical_function((const gsl_vector *) &cv); return 0; }