Max API  8.0.2
Symbols

Max maintains a symbol table of all strings to speed lookup for message passing. More...

Data Structures

struct  t_symbol
 The symbol. More...
 

Functions

t_symbolgensym (C74_CONST char *s)
 Given a C-string, fetch the matching t_symbol pointer from the symbol table, generating the symbol if neccessary. More...
 
t_symbolgensym_tr (const char *s)
 Given a C-string, fetch the matching t_symbol pointer from the symbol table, generating and translating the symbol if neccessary. More...
 

Detailed Description

Max maintains a symbol table of all strings to speed lookup for message passing.

If you want to access the bang symbol for example, you’ll have to use the expression gensym("bang"). For example, gensym() may be needed when sending messages directly to other Max objects such as with object_method() and outlet_anything(). These functions expect a t_symbol*, they don’t gensym() character strings for you.

The t_symbol data structure also contains a place to store an arbitrary value. The following example shows how you can use this feature to use symbols to share values among two different external object classes. (Objects of the same class can use the code resource’s global variable space to share data.) The idea is that the s_thing field of a t_symbol can be set to some value, and gensym() will return a reference to the Symbol. Thus, the two classes just have to agree about the character string to be used. Alternatively, each could be passed a t_symbol that will be used to share data.

Storing a value:

s = gensym("some_weird_string");
s->s_thing = (t_object *)someValue;

Retrieving a value:

s = gensym("some_weird_string");
someValue = s->s_thing;

Function Documentation

◆ gensym()

◆ gensym_tr()

t_symbol* gensym_tr ( const char *  s)

Given a C-string, fetch the matching t_symbol pointer from the symbol table, generating and translating the symbol if neccessary.

Parameters
sA C-string to be looked up in Max's symbol table and then translated
Returns
A pointer to the t_symbol in the symbol table.