[sane-devel] Re: Question regarding compiler warnings in sane-backends/sanei

Henning Meier-Geinitz henning@meier-geinitz.de
Thu, 6 Dec 2001 19:12:39 +0100


Hi,

On Wed, Dec 05, 2001 at 10:42:33PM -0500, Stephen Torri wrote:
> I keep getting warnings for when we cast a SANE_String_Const into a 
> SANE_String*. For example looking at sanei_wire.c in the sane-backends at 
> line 432:
> 
> sanei_w_string(w, (SANE_String *) & v->name);
> 
> I cannot see a reason why gcc-2.96-98 gives me a warning for this. Does 
> anyone have an idea why this is coming up? 

v->name is declared const. Now you use (SANE_String *) to access it as
if it wasn't constant. You could change the v->name in sanei_w_string
without the compiler noticing this. That's why it prints the warning.

> Would it be wrong if we are using SANE_String for the name string in the 
> SANE_DEVICE

Please, no changes to the current standard :-) And in principle, the
"const" is correct. The name shouldn't change once it's set up.

> or should we change the arguments of sanei_w_string to accept 
> a SANE_String_Const? 

sanei_w_string must be able to change the address of its argument to
return data from the wire (all these functions work two-way).

> If we are changing the value of name then it makes sense to do the
> later. Vice versa.

What you can do, is to use copies of v->name. I've done this in the
mustek backend to avoid similar warnings.

Bye,
  Henning