Forums > Dev

std library use in C++ external (eg std::string and std::stoull)


July 3, 2013 | 5:55 pm

Hi,
for synchronisation, I need to send an unsigned long long to my external. I currently compile as .cpp (which works fine if you simply cast the object as a (t_object*))
however, although I can get the unsigned lon long into the object (as a message)
I can;t seem to convert it to unsigned long long using std::stoull
and std::string also gives problems
why is that? how could the standard library added/used?
or is tehre a workaround?

void synchroniser_offset(t_synchroniser *x, t_symbol *s, long argc, t_atom *argv)
{
long i;
t_atom *ap;

post("message selector is %s",s->s_name);
//here s->s_name is the value I’m interested in converting to unsigned long long

}

Thanks!

July 3, 2013 | 6:07 pm

okay, so I seem to have got somewhere using;
#include

and

post("message selector is %s",s->s_name);
unsigned long long ul = strtoull (s->s_name, NULL, 0);
post("unsigned %llu ", ul);

perhaps it’s using the C version of the standard library?
being careful to use C-string types, not std::string s?

but the code above works. Any comments appreciated though so I understand why the issue arose.

May 21, 2015 | 6:06 am

more of a postscipt here, in case anyone comes across this, you cast to a t_class not a t_object to use cpp within max external:

t_myobject *x = (t_myobject *)object_alloc((t_class*)myobject_class)

and the external is [myobject]

May 27, 2015 | 4:02 pm

You are creating an instance of your class. It can be cast as a t_myobject or a t_object if you want because the first item in your t_myobject struct is a t_object *.

May 27, 2015 | 4:24 pm

thanks Emmanuel.
how about the (t_class*) part of the above?
that’s how I tend to use a cpp extension and have C++ classes included in the external. My last comment is just trying to provide the correct information on doing that.

Viewing 5 posts - 1 through 5 (of 5 total)

Forums > Dev