\lstinline of the listings package doesn't work in math mode. When I try to use it, I get the error that \ttfamily is invalid in math mode.
However, when reasoning about program semantics, it is often necessary to put snippets of program code inside mathematical constructs and, ideally, this would be done with \lstinline in order to keep a consistent style between inline snippets and larger code blocks.
There are several ad-hoc case-by-case solutions, of course. I've been able to make \lstinline work within a \text command, being extra careful to escape certain characters. Sometimes I don't use \lstinline at all and format the code snippet by hand. Neither is really convenient.
Is there a generally applicable solution? Ideally I could just use \lstinline in math mode (well, its \lstMakeShortInline shortcut anyway) without any error. I do occasionally use mathescape inside code snippets. Having that still work would be nice, but is not essential.

amsmath, try wrapping thelstinlinestring in\text{...}. (i don't uselistings, so this is totally off the wall.) – barbara beeton Aug 06 '13 at 19:13\textsometimes works (I think thelistingsdeveloper(s) had a hard time making that sort of thing work, actually). But then I need to escape special characters. All in all, it's more verbose than I'd like. My question is: can I make\lstinlinework as is? – mhelvens Aug 06 '13 at 19:21