t[iny]cc says,
/home/mirar/pike/src/modules/HTTPLoop/accept_and_parse.c:550: cannot cast 'const struct svalue' to 'struct svalue'
I assume this is because,
550: assign_svalue_no_free(sp++, &arg->args);
#define assign_svalue_no_free_unlocked(X,Y) do {\ struct svalue _tmp;\
struct svalue *_to=(X);\ const struct svalue *_from=(Y);\
check_type(_from->type); check_refs(_from);\
*_to=_tmp=*_from;\
if(_tmp.type <= MAX_REF_TYPE) add_ref(_tmp.u.dummy);\ }while(0)
it works if I remove the "const". But is it the correct solution? const in C confuses me.
On Thu, Mar 11, 2004 at 08:35:02PM +0100, Mirar @ Pike developers forum wrote:
it works if I remove the "const". But is it the correct solution? const in C confuses me.
Basically, if you know what you are doing, you can safely remove "const" declaration - it is used (mostly) only to prevent accidental modification access (i.e. - obvious attempt to modify, visible to compiler at compile-time).
Of course, the presence of "const" won't make any structure read-only ( not in standard C, at least) :)
Regards, /Al
Basically, if you know what you are doing, you can safely remove "const" declaration -
In this case, since the const is used in an exported header file, you would have to know what _everybody else_ is doing as well, including external module writers. Or they would have to know what they are doing. I don't think either can be assumed to be true.
/ Marcus Comstedt (ACROSS) (Hail Ilpalazzo!)
Previous text:
2004-03-11 20:58: Subject: Re: const
On Thu, Mar 11, 2004 at 08:35:02PM +0100, Mirar @ Pike developers forum wrote:
it works if I remove the "const". But is it the correct solution? const in C confuses me.
Basically, if you know what you are doing, you can safely remove "const" declaration - it is used (mostly) only to prevent accidental modification access (i.e. - obvious attempt to modify, visible to compiler at compile-time).
Of course, the presence of "const" won't make any structure read-only ( not in standard C, at least) :)
Regards, /Al
/ Brevbäraren
"const" means that the contants of the object can not be modified (through that name; it may be aliased). In this case, the variable _tmp, which is not const, is assigned from *_from, which is const. But that's no problem, since this operation just modifies _tmp, not *_from. So it feels like the compiler is in error. But I haven't checked the standard...
/ Marcus Comstedt (ACROSS) (Hail Ilpalazzo!)
Previous text:
2004-03-11 20:33: Subject: const
t[iny]cc says,
/home/mirar/pike/src/modules/HTTPLoop/accept_and_parse.c:550: cannot cast 'const struct svalue' to 'struct svalue'
I assume this is because,
550: assign_svalue_no_free(sp++, &arg->args);
#define assign_svalue_no_free_unlocked(X,Y) do {\ struct svalue _tmp;\
struct svalue *_to=(X);\ const struct svalue *_from=(Y);\
check_type(_from->type); check_refs(_from);\
*_to=_tmp=*_from;\
if(_tmp.type <= MAX_REF_TYPE) add_ref(_tmp.u.dummy);\ }while(0)
it works if I remove the "const". But is it the correct solution? const in C confuses me.
/ Mirar
pike-devel@lists.lysator.liu.se