3
$\begingroup$

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

'a'
$\endgroup$
2
$\begingroup$

You could do

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

giving

"a"[0]

maybe wrap it in CParentheses.

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

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

gives

a = 'a'
|improve this answer|||||
$\endgroup$
  • 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.