Deprecated conversion from string to 'char*'

Feb 19, 2010 at 11:58pm

Deprecated conversion from string to 'char*'

Hi,

after upgrading to Snow Leopard and the latest Xcode (with a possibly new version of GCC) I started getting tons of this warning:

Deprecated conversion from string to ‘char*’

After examining the problem I realized that SDK functions like gensym, object_post etc. are declared with char * arguments instead of const char *. Although this is not a de facto error, C/C++ function declaration guidelines usually recommend declaring every argument that won’t be changed by the function as const (I suppose they introduced this particular warning to remind developers about this fact). There are many reasons why this guideline exists, and although I’m sure I could disable this particular warning with some compiler flag, I decided to overwrite the definitions in the respective SDK headers (mainly ext_proto.h) as this makes a cleaner situation.

Would it be possible for the developers of the SDK to fix this small inconvenience in a future release of the SDK?

Thanks,
Adam

#48628
Feb 22, 2010 at 11:46am

Thanks. We’re aware of this inconvenience.

The biggest offender here is gensym() and we are working on making future SDK versions more const-aware. The interim solution is to modify the SDK as you have done, or to define a macro or inline function that you can use as a substitute for the functions like gensym. E.g.:

inline t_symbol* my_gensym(const char* s)
{
    return gensym((char*)s);
}
#174851
Nov 14, 2012 at 2:47am

Hi Tim,

it seems that this issue is back with the Max 6.0.4 SDK, at least with gensym_tr(), str_tr() and sprintf_tr(). I’ll let you know if I find more.

Cheers,
Ádám

#174852
Nov 21, 2012 at 12:04pm

Thanks — I’ll try to make sure I plug those holes…
Tim

#174853
Jan 2, 2013 at 11:50am

Hi Tim,

I think that I’ve found another two: table_get() and table_dirty().

Cheers,
Ádám

#174854
Jul 23, 2013 at 7:08am

Hi Tim,

just updated to SDK 6.1.3 and noticed that table_get() and table_dirty() was `fixed back’ (or perhaps I modified them manually in an earlier SDK). Anyway, it seems that they’re expecting t_symbol * instead of const t_symbol *.

Cheers,
Ádám

#256893
Jul 23, 2013 at 7:16am

Hi — not sure I understand the problem… These are t_symbol* rather than char*. Can you provide the warning or error that the compiler is giving you?

Thanks,
- .. –

#256894
Jul 23, 2013 at 9:30am

Hi,

it turns out that I messed up something during the upgrade process. Of course, due to the usage of C74_SYM_LINKER_FLAGS, the problem no longer happens in Max 6. However, in Max 5, the following code:

const t_symbol * bufferName;
long **          data;
long             size;

table_get ( bufferName, & data, & size );

will cause a compiler error: invalid conversion from 'const t_symbol*' to 't_symbol*'.

Cheers,
Ádám

#256916
Jul 25, 2013 at 6:40am

Looks like you will need to do a cast to throw away the constness in this call.

table_get ( (t_symbol*)bufferName, & data, & size );
#257100

You must be logged in to reply to this topic.