I am aware of CConstant and CString, but neither can output the single-char literal


You could do

CArray[CString@"a", 0] // ToCCodeString



maybe wrap it in CParentheses.

Alternatively, just put it there verbatim (losing the type information):

CAssign[a, "'a'"] // ToCCodeString


a = 'a'
|improve this answer|||||
  • 1
    $\begingroup$ Just put it there verbatim, there is really no need for the complication with CArray. Generally, bits of C code can be written in a string. You only need symbolic representation when you want to manipulate it as an expression. $\endgroup$ – Szabolcs Feb 12 '17 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.