Alex Rivera | Logout

Why is a type qualifier on a return type meaningless?

Asked 2009-10-22T13:27:34.793
25

Say I have this example:

char const * const
foo( ){
   /* which is initialized to const char * const */
   return str;
}

What is the right way to do it to avoid the compiler warning "type qualifier on return type is meaningless"?

c++ c
Edit
Report

1 Answer

6

In C, because function return values, and qualifying values is meaningless.
It may be different in C++, check other answers.

const int i = (const int)42; /* meaningless, the 42 is never gonna change */
int const foo(void); /* meaningless, the value returned from foo is never gonna change */

Only objects can be meaningfully qualified.

const int *ip = (const int *)&errno; /* ok, `ip` points to an object qualified with `const` */
const char *foo(void); /* ok, `foo()` returns a pointer to a qualified object */
answered 2009-10-22T13:42:58.620

Your Answer