﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
6241	Generated Cpp code for Modelica functions using uninitialized varaibles	Andreas Heuermann	Andreas Heuermann	"Running 

{{{
loadModel(Modelica, {""3.2.2""}); getErrorString();
setCommandLineOptions(""-d=newInst --simCodeTarget=Cpp""); getErrorString();
simulate(Modelica.Media.Examples.Tests.MediaTestModels.IdealGases.SimpleNaturalGas); getErrorString();
}}}

will generate `OMCppModelica.Media.Examples.Tests.MediaTestModels.IdealGases.SimpleNaturalGasFunctions.cpp` with

{{{
//if outvars missing
void /*_omcQ_24DER_24Modelica_24PMedia_24PExamples_24PTests_24PMediaTestModels_24PIdealGases_24PSimpleNaturalGas_24Pvolume_24PMedium_24Ph_5F_5FTXRetType */ Functions::_omcQ_24DER_24Modelica_24PMedia_24PExamples_24PTests_24PMediaTestModels_24PIdealGases_24PSimpleNaturalGas_24Pvolume_24PMedium_24Ph_5F_5FTX(double T_, BaseArray<double>& X_, bool exclEnthForm_, int refChoice_, double h_off_, double _omcQ_24Modelica_24PMedia_24PExamples_24PTests_24PMediaTestModels_24PIdealGases_24PSimpleNaturalGas_24Pvolume_24PMedium_24Ph_5FTX_24funDERT_, BaseArray<double>& _omcQ_24Modelica_24PMedia_24PExamples_24PTests_24PMediaTestModels_24PIdealGases_24PSimpleNaturalGas_24Pvolume_24PMedium_24Ph_5FTX_24funDERX_, double _omcQ_24Modelica_24PMedia_24PExamples_24PTests_24PMediaTestModels_24PIdealGases_24PSimpleNaturalGas_24Pvolume_24PMedium_24Ph_5FTX_24funDERh_5Foff_,_omcQ_24DER_24Modelica_24PMedia_24PExamples_24PTests_24PMediaTestModels_24PIdealGases_24PSimpleNaturalGas_24Pvolume_24PMedium_24Ph_5F_5FTXRetType & output )
{
[...]
  /* varOutput varInits(_omcQ_24Modelica_24PMedia_24PExamples_24PTests_24PMediaTestModels_24PIdealGases_24PSimpleNaturalGas_24Pvolume_24PMedium_24Ph_5FTX_24funDERh_) */ 
  do
  {

    {
      [...]
      int tmp51;
      [...]
      if (!tmp51) throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,""Internal error"");
      [...]
    }
    [...]
  }
  [...]
}
}}}

Please note that variable `tmp51` is not used at all, so whenever `tmp51` happens to be initialized with `0` the function will throw an error.

The Cpp code generation for this was a copy of the C code generation and is still very similar. When generating code for the C target the generated code looks very similar, but doesn't have this error."	defect	closed	high	1.17.0	Code Generation	v1.17.0-dev	fixed	Cpp, function	Niklas Worschech Rüdiger Franke
