* const qualifier on function return types.
@ 2001-12-19 13:20 Lowell Johnson
2001-12-19 13:20 ` Brian Gough
2001-12-19 13:20 ` Brian Gough
0 siblings, 2 replies; 5+ messages in thread
From: Lowell Johnson @ 2001-12-19 13:20 UTC (permalink / raw)
To: gsl-discuss
Hello,
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.
const gsl_vector gsl_vector_const_subvector (const gsl_vector *v,
size_t i, size_t n);
...
I do not get these warnings on Linux/gcc using the following command line:
gcc -DHAVE_CONFIG_H -I. -I. -I.. -I.. -O -funsigned-char \
-fwritable-strings -Wall -c cholesky.c
I searched the mailing list archive and saw a short discussion of this and
whether it is ANSI C. I didn't see any mention of the reason for applying
the const qualifier.
What is the purpose of applying a const qualifier to a return value? Is it
so that we can see the return value but not change it?
The library builds and works fine, but I would rather not have pages of
warnings in my applications that use the GSL.
Any suggestions?
Thanks.
-- Lowell
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: const qualifier on function return types.
2001-12-19 13:20 const qualifier on function return types Lowell Johnson
@ 2001-12-19 13:20 ` Brian Gough
2001-12-19 13:20 ` Brian Gough
1 sibling, 0 replies; 5+ messages in thread
From: Brian Gough @ 2001-12-19 13:20 UTC (permalink / raw)
To: Lowell Johnson; +Cc: gsl-discuss
Lowell Johnson writes:
> cc-3303 cc: WARNING File = ../gsl/gsl_vector_double.h, Line = 78
> A type qualifier on a return type is meaningless.
>
> I searched the mailing list archive and saw a short discussion of
> this and whether it is ANSI C. I didn't see any mention of the
> reason for applying the const qualifier.
> What is the purpose of applying a const qualifier to a return
> value? Is it so that we can see the return value but not change
> it?
That was the intention, but it doesn't work. The const on those
return types is meaningless, as the compiler says.
The cause of the warnings is functions like
const gsl_vector gsl_vector_const_view (const gsl_vector * v, ..)
The logic behind the return type was to preserve constness when
creating vector views, so that a view of a "const gsl_vector *" would
also be const. It doesn't actually work because the views are
returned as structs and C doesn't preserve constness when copying
structs.
I'll have to do something about it .. it is unsatisfactory right now.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: const qualifier on function return types.
2001-12-19 13:20 ` Brian Gough
@ 2001-12-19 13:20 ` Lowell Johnson
2001-12-19 13:20 ` Brian Gough
0 siblings, 1 reply; 5+ messages in thread
From: Lowell Johnson @ 2001-12-19 13:20 UTC (permalink / raw)
To: Brian Gough; +Cc: gsl-discuss
On Thu, 28 Jun 2001, Brian Gough wrote:
[snip]
> 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.
[snip]
Here are the results:
(Copied your test case to a file named gsl_test.c.)
~/tmp> make gsl_test
cc -O -s -n32 -mips3 -Wl,-woff,85 -fullwarn -o gsl_test gsl_test.c
~/tmp> ./gsl_test
v1 = 123.4 .. 9.123
v2 = 567.8 .. 9.123
v2 = 567.8 .. 9.123
v2 = 568.8 .. 10.123
v2 = 568.8 .. 10.123
Let me know if you need additional info.
-- Lowell
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: const qualifier on function return types.
2001-12-19 13:20 const qualifier on function return types Lowell Johnson
2001-12-19 13:20 ` Brian Gough
@ 2001-12-19 13:20 ` Brian Gough
2001-12-19 13:20 ` Lowell Johnson
1 sibling, 1 reply; 5+ messages in thread
From: Brian Gough @ 2001-12-19 13:20 UTC (permalink / raw)
To: Lowell Johnson; +Cc: gsl-discuss
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;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: const qualifier on function return types.
2001-12-19 13:20 ` Lowell Johnson
@ 2001-12-19 13:20 ` Brian Gough
0 siblings, 0 replies; 5+ messages in thread
From: Brian Gough @ 2001-12-19 13:20 UTC (permalink / raw)
To: Lowell Johnson; +Cc: gsl-discuss
Lowell Johnson writes:
> Here are the results:
>
> (Copied your test case to a file named gsl_test.c.)
>
> ~/tmp> make gsl_test
> cc -O -s -n32 -mips3 -Wl,-woff,85 -fullwarn -o gsl_test gsl_test.c
> ~/tmp> ./gsl_test
> v1 = 123.4 .. 9.123
Thanks. No warnings, looks good. I will implement that scheme. Once
it is done we can release gsl-0.9 which will be the final testing
release.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2001-12-19 13:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-19 13:20 const qualifier on function return types Lowell Johnson
2001-12-19 13:20 ` Brian Gough
2001-12-19 13:20 ` Brian Gough
2001-12-19 13:20 ` Lowell Johnson
2001-12-19 13:20 ` Brian Gough
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).