This is the mail archive of the
gsl-discuss@sources.redhat.com
mailing list for the GSL project.
Re: const qualifier on function return types.
- To: Lowell Johnson <ldjohn at usgs dot gov>
- Subject: Re: const qualifier on function return types.
- From: Brian Gough <bjg at network-theory dot co dot uk>
- Date: Thu, 28 Jun 2001 21:56:19 +0100 (BST)
- CC: gsl-discuss at sources dot redhat dot com
- References: <01061510380302.06977@edclxw5>
Lowell Johnson writes:
> On IRIX using the MIPSPro C compiler, I get many warnings of the following
> sort (GSL 0.7 -- 0.8, at least):
>
> cc -DHAVE_CONFIG_H -I. -I. -I.. -I.. -O -s -n32 -mips3 -Wl,-woff,85 \
> -fullwarn -c cholesky.c
> ...
> cc-3303 cc: WARNING File = ../gsl/gsl_vector_double.h, Line = 78
> A type qualifier on a return type is meaningless.
>
> The library builds and works fine, but I would rather not have pages of
> warnings in my applications that use the GSL.
If you have a moment would you mind trying out the program below with
the IRIX compiler. It's my proposal for a scheme that avoids the
const problem. It works with GCC but I'd like to hear if it works for
you on IRIX before I go and modify all the view-related functions and
references to them. Thanks.
Brian
#include <stdio.h>
typedef struct {
double * data;
int size;
} vector ;
typedef struct {
vector v;
} view ;
typedef union {
vector _v;
const vector v;
} const_view;
void vinc (vector * v)
{
int i;
for (i = 0; i < v->size; i++)
v->data[i] += 1.0;
}
double vsum (const vector * v)
{
int i; double s=0.0;
for (i = 0; i < v->size; i++)
s+= v->data[i] ;
return s;
}
view mkview (const vector * v)
{
view w;
w.v = *v;
w.v.data++;
w.v.size = v->size - 1;
return w;
}
const_view mkcview (const vector * v)
{
const_view w;
w._v = *v;
w._v.data++;
w._v.size = v->size - 1;
return w;
}
int
main (void)
{
double x[] = {123.4, 567.8, 9.123};
vector v1;
v1.data = x;
v1.size = 3;
printf("v1 = %g .. %g\n", v1.data[0], v1.data[v1.size-1]);
{
const_view cv = mkcview (&v1);
view v = mkview (&v1);
printf("v2 = %g .. %g\n", cv.v.data[0], cv.v.data[cv.v.size-1]);
printf("v2 = %g .. %g\n", v.v.data[0], v.v.data[v.v.size-1]);
vinc(&v.v);
vsum(&cv.v);
printf("v2 = %g .. %g\n", cv.v.data[0], cv.v.data[cv.v.size-1]);
printf("v2 = %g .. %g\n", v.v.data[0], v.v.data[v.v.size-1]);
}
return 0;
}