next up previous contents index
Next: 3.2.2 The General XSB Up: 3.2.1 The XSB API Previous: 3.2.1 The XSB API   Contents   Index

3.2.1.1 An Example using Fixed Strings

Figure 3.2: Calling XSB using the Fixed String Interface
\begin{figure}\begin{small}
\begin{verbatim}int retsize = 15;
char *return_s...
...Tc return_string,15,&anslen,''\vert'');
}\end{verbatim}
\end{small}\end{figure}

Figure 3.2 shows a fragment of code indicating how the previous example would be modified if the fixed-string interface were used. Note that return_string now becomes a pointer to explicitly malloc-ed memory. To open the query p(X,Y,Z) the function xsb_query_string_string_b() is called, with the _b indicating that a fixed buffer is being used rather than a VarString. The call is similar to xsb_query_string_string(), except that the length anslen of the buffer pointed to by return_string is now also required. If the answer to be returned (including separators) is longer than anslen, xsb_query_string_string_b() will return XSB_OVERFLOW. If this happens, a new answer buffer can be used (here the old one is realloc-ed) and the answer retrieved via xsb_get_last_answer_string. Similarly, further answers are obtained via xsb_next_string_b() whose length must be checked. Thus the only difference between the fixed-string level and the VarString level is that the length of each answer should be checked and xsb_get_last_answer_string() called if necessary.


next up previous contents index
Next: 3.2.2 The General XSB Up: 3.2.1 The XSB API Previous: 3.2.1 The XSB API   Contents   Index
Terrance Swift 2007-10-06