Hi all,
I am trying to compare two symbols, one incoming in a list into an external and the other one stored internally in the external.
It compiles fine, but I don't get a match.
c code is below. Ideas on what I'm missing?
J
void testtext_input(t_testtext *x, t_symbol *selector, int argcount, t_atom *argvec) { int i; const t_symbol *storedsymbol = gensym("mysymbol"); for (i = 0; i < argcount; i++) { if (argvec[i].a_type == A_SYMBOL) { if ( argvec[i].a_w.w_symbol->s_name == storedsymbol) post("found match!"); } }
Strange things like this can happen if someone inadvertently writes a new string into an existing symbol... i.e., never do this: strcat(sym->s_name, "cat").
MAybe there was already a symbol somewhere else whose name is "cat" and then you'll have 2 symbols with teh same name but different addresses. (I've seen people do this, in various ways, before).
cheers Miller
On Sat, May 03, 2014 at 03:22:19AM -0400, Jaime E Oliver wrote:
Hi all,
I am trying to compare two symbols, one incoming in a list into an external and the other one stored internally in the external.
It compiles fine, but I don't get a match.
c code is below. Ideas on what I'm missing?
J
void testtext_input(t_testtext *x, t_symbol *selector, int argcount, t_atom *argvec) { int i; const t_symbol *storedsymbol = gensym("mysymbol"); for (i = 0; i < argcount; i++) { if (argvec[i].a_type == A_SYMBOL) { if ( argvec[i].a_w.w_symbol->s_name == storedsymbol) post("found match!"); } } _______________________________________________ Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
On 05/03/2014 09:22 AM, Jaime E Oliver wrote:
Hi all,
I am trying to compare two symbols, one incoming in a list into an external and the other one stored internally in the external.
It compiles fine, but I don't get a match.
c code is below. Ideas on what I'm missing
the whole idea about symbols is, that you can do a pointer comparision of the *symbol*.
so it should be as simple as: if(argvec[i].a_type == A_SYMBOL && argvec[i].a_w.w_symbol == storedsymbol) post("found match");
if (argvec[i].a_type == A_SYMBOL) { if ( argvec[i].a_w.w_symbol->s_name == storedsymbol) post("found match!");
the ->s_name field of the symbol is the pointer to the actual C-string, whereas storedsymbol is a pointer to the symbol. so you are doing a compare ((const char*)cstr == (t_symbol*)sym), which is clearly wrong.
fgmsadr IOhannes
Thanks to both, it makes sense and it works now.
J
On May 3, 2014, at 4:42 AM, IOhannes m zmölnig zmoelnig@iem.at wrote:
On 05/03/2014 09:22 AM, Jaime E Oliver wrote:
Hi all,
I am trying to compare two symbols, one incoming in a list into an external and the other one stored internally in the external.
It compiles fine, but I don't get a match.
c code is below. Ideas on what I'm missing
the whole idea about symbols is, that you can do a pointer comparision of the *symbol*.
so it should be as simple as: if(argvec[i].a_type == A_SYMBOL && argvec[i].a_w.w_symbol == storedsymbol) post("found match");
if (argvec[i].a_type == A_SYMBOL) { if ( argvec[i].a_w.w_symbol->s_name == storedsymbol) post("found match!");
the ->s_name field of the symbol is the pointer to the actual C-string, whereas storedsymbol is a pointer to the symbol. so you are doing a compare ((const char*)cstr == (t_symbol*)sym), which is clearly wrong.
fgmsadr IOhannes
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list