﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
6055	Bug when passing Boolean arrays as external function arguments	Bernhard Thiele	Andreas Heuermann	"In the model below a Boolean array is passed to an external function. The returned Boolean array should be identical. This works as expected when using the Cpp run-time, but fails for the default C run-time.

{{{#!modelica
model ExternalArrayBug
  ""Shows an OMC C run-time bug when passing Boolean arrays""
  output Boolean u[4](each start=false,each fixed=true);
  output Boolean y[4](each start=false,each fixed=true);

protected
function booleanIdentity
  extends Modelica.Icons.Function;
  input Boolean u[:];
  output Boolean y[size(u,1)];
  external ""C"" boolean_identity(u, size(u,1), y, size(y,1))
  annotation(Include = ""
  #include \""ModelicaUtilities.h\""
  void boolean_identity(const int *u, size_t u_n, int *y, size_t y_n) {
    for (int i=0; i<u_n; ++i) {
      ModelicaFormatMessage(\""u[%d]=%d\\n\"", i, u[i]);
      y[i] = u[i] == 0 ? 0 : 1;
    }
  }
  "");
end booleanIdentity;

equation
  when sample(0,0.1) then
    u = not pre(u);
    y = booleanIdentity(u);
  end when;
end ExternalArrayBug;
}}}

Below is part of the ModelicaFormatMessage output which I get running OpenModelica 1.16.0~dev-541-gfd2d61b using Linux.

{{{
u[0]=16843009
u[1]=0
u[2]=0
u[3]=0
u[0]=0
u[1]=1
u[2]=0
u[3]=0
u[0]=16843009
u[1]=0
u[2]=0
u[3]=0
u[0]=0
u[1]=1
u[2]=0
u[3]=0
}}}"	defect	new	normal		Run-time	v1.16.0-dev			
