On 20/06/11 20:51, MacArthur, Ian (SELEX GALILEO, UK) wrote:
>> What I'd suggest doing is simply explicitly casting the first
>> parameter
>> to a char*; this _should_ fix your issue (at least it doesn't
>> create any
>> on gcc under Ubuntu 10.10).
>> I suspect the only person who could confirm such a fix would be Ian,
>> though....
> Yes, that does work, e.g:
>
> (Fl_File_Chooser2.cxx, line 870:)
>
> //      fltk3::alert("%s",existing_file_label); // error
>        fltk3::alert((char*)"%s",existing_file_label); // ok
>
> (This pattern is required in several places, and in Fl_Text_Buffer.cxx,
> Fl_Function_Type.cxx, etc...)
>
> Though I have concerns about casting a "fixed" string like that just to
> "trick" the compiler into doing the "obvious" conversion.

 From what I understand of the "mechanics" of const vs. non-const, it 
shouldn't have any effect on the mechanics of the executable. "const" 
just forces the variable / etc. into read-only memory which has no write 
access (hence writing to const strings causes a segmentation fault). 
Further, if I were to declare an array, say 'char my_string[] = "Sample 
string";', the compiler will optimise this to a const char [] and the 
only way to avoid this is either a) the keyword "explicit" or b) a cast 
with (char*).
Based on those, I don't see the problem with an explicit cast, though I 
do agree that it's not the cleanest solution.

> I suppose the best bet *might* be to add a third option that expands to
> (const char *, const char*) that would then take precedence over either
> of the ambiguous cases here and so avoid the problem...?
TBH it looks like existing_file_label shouldn't be declared const 
anyway, and on top of that I'm not sure why the first parameter in 
"alert" isn't const - it seems to me that this parameter should always 
be const? This no doubt makes sense to Matt though!
If existing_file_label were to be changed to char*, this should then be 
matched to the second version of alert()....

Ben

_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to