0

I would like to declare an array of pointer with an initialization

Apb : array [0..2] of pointer to bool := adr(r0), adr(r1), adr(r2);

Where r0, r1, r2 are declared in Modbus like Bitwise holding register. I got an error: Wrong initial value.

In case:

Apb : array [0..2] of pointer to bool;
Apb[0]^ := r0;

Everything works as I want.

user2097818
  • 1,821
  • 3
  • 16
  • 34
Ulrich Von Rekkenin
  • 352
  • 1
  • 3
  • 14

1 Answers1

1

I think that POU variable declarations do not want function calls in them or even variables assigned to other variables.

The only way to have variables in your declaration is to use VAR_CONSTANTs. You will still have to do some legwork, but it can make larger-scale substitutions easier to manage.

There is also a way to use dynamic values using pragmas (I never really use pragmas although, so Im not certain of how powerful it is).


Coming from more standard programming languages, this one has similar rules and constructs as C, but not nearly as much flexibility, dreadful syntax, and nothing even resembling 'void' types. I ended up using python templates to help generate POU variable declaration headers because the allowed syntax is quite strict, leading to excessively verbose declarations.

user2097818
  • 1,821
  • 3
  • 16
  • 34
  • Constants are not variables by definition. The CoDeSys compiler only accepts statically known values for initialization and neither functions nor variables can be resolved at compile time. – Yegor May 20 '15 at 06:32