5
$\begingroup$

The CSwitch manual page gives the example

CSwitch["val", 1, CAssign["i", 10], CBreak[], 2, CAssign["i", 3], 
  CBreak[]] // ToCCodeString

which generates this illegitimate C code:

switch ( val)
{
case 1:
i = 10;

case break;:
2;

case i = 3:
break;
}

And I cannot even get it to produce just the first case, i.e.

switch ( val)
{
case 1:
i = 10;
break;
}

I tried removing the rest from the first example,

CSwitch["val", 1, CAssign["i", 10], CBreak[]] // ToCCodeString

but this gives

ToCCodeString::unk: An unknown element, CSwitch[val,1,CAssign[i,10],CBreak[]], was found when generating code >>

CUnknownElement[CSwitch[val, 1, CAssign[i, 10], CBreak[]]]

and

CSwitch["val", 1, {CAssign["i", 10], CBreak[]}] // ToCCodeString

generates the right code but again gives a message.

Also, the syntax-highlighting for CSwitch should probably tolerate any amount of arguments.

Is there something wrong with my setup or can somebody confirm this?

This is 10.4.

$\endgroup$
  • $\begingroup$ CSwitch is a little bent, but it's documentation shows serious fractures. $\endgroup$ – m_goldberg Aug 11 '16 at 2:28
  • $\begingroup$ Was this reported? I still see it in the very latest version. Shouldn't we add the bugs tag? $\endgroup$ – Gustavo Delfino Jan 24 at 22:15
4
$\begingroup$

The documentation for CSwitch looks like it was written by somebody who didn't understand what the SymbolicC package or, for that matter, what a C switch is supposed to do. The following produces something more like C code and makes more sense as Mathematica code.

Needs["SymbolicC`"]
CSwitch["val",
  1, {CAssign["i", 10], CBreak[]},
  2, {CAssign["i", 3], CBreak[]}] // ToCCodeString

ccode

Still I would say that the SymbolicC package is very much a work in progress.

$\endgroup$
  • $\begingroup$ Is it an officially supported package, i.e. would you contact support about this? $\endgroup$ – masterxilo Aug 11 '16 at 8:07
  • 1
    $\begingroup$ @masterxilo. Yes, it is an officially provided package and should be supported by Wolfram Research, Inc. I encourage you to contact WRI tech support concerning what you have found. $\endgroup$ – m_goldberg Aug 11 '16 at 8:37
  • $\begingroup$ @masterxilo Yes, report it. Similar bugs I reported in this package in the past were fixed. $\endgroup$ – Szabolcs Sep 3 '17 at 21:27

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.