DXL Function Overload: Unassigned Variable

Using DOORS 9.6.0.1 (build 96071), I am seeing strange behavior when doing very simple function overloads. With the following test code:

void Foo (int i)
{
  print i

  int j = 4
}

void Foo (void)
{
  Foo (2)
}

Foo

I get Dxl output

-R-E- DXL: <Line:3> unassigned variable (i)
Backtrace:
    <Line:10> 
    <Line:13> 
-I- DXL: execution halted

When I swap the order of lines 3 and 4 (put the declaration of local variable j before the print statement) or delete variable j completely, things are fine. Does anyone else see this behavior?

Thanks,

- Joel


JoelKuehner - Thu Aug 18 13:05:15 EDT 2016

Re: DXL Function Overload: Unassigned Variable
DOORSHAM - Thu Aug 18 13:35:39 EDT 2016

Do this:

void Foo (int i)
 {   print i

  int j = 4
 }

void Foo ()
 {   Foo (2)
 }

Foo

Re: DXL Function Overload: Unassigned Variable
JoelKuehner - Thu Aug 18 16:28:06 EDT 2016

Ok; that worked. But why? Should we never specify (void) for DXL function parameter lists?

Thanks,

- Joel

Re: DXL Function Overload: Unassigned Variable
DOORSHAM - Fri Aug 19 03:29:01 EDT 2016

JoelKuehner - Thu Aug 18 16:28:06 EDT 2016

Ok; that worked. But why? Should we never specify (void) for DXL function parameter lists?

Thanks,

- Joel

I try to use what work and abandon what doesn't work.  However, if you want to continue to use what doesn't work, feel free to do so.

Re: DXL Function Overload: Unassigned Variable
JoelKuehner - Fri Aug 19 23:17:42 EDT 2016

DOORSHAM - Fri Aug 19 03:29:01 EDT 2016

I try to use what work and abandon what doesn't work.  However, if you want to continue to use what doesn't work, feel free to do so.

My original post already stated that I had a work-around (declaring locals before using parameters). I am trying to determine if anyone else out there sees the same thing, and if anyone can explain the behavior.

 

I try to understand why what I use works or does not work.

 

Thanks,

- Joel

 

Re: DXL Function Overload: Unassigned Variable
Mathias Mamsch - Sat Aug 20 05:23:38 EDT 2016

JoelKuehner - Fri Aug 19 23:17:42 EDT 2016

My original post already stated that I had a work-around (declaring locals before using parameters). I am trying to determine if anyone else out there sees the same thing, and if anyone can explain the behavior.

 

I try to understand why what I use works or does not work.

 

Thanks,

- Joel

 

People tend to forget that DXL and C while having a similar syntax are very different from another. I do not know how else people would get the idea to declare "void" parameters, but void is not a type in DXL. Therefore you must not use it for parameters, except as the return value of a function parameter

void myFunc (void callback(int, string))  { ... }

That programs using "void" as a parameter still translate correctly is a misbehaviour of the DXL parser. There are lots of problems like this and most of them are mentioned on the forum. If you search for parser problem or parser error you will likely get some results.

As a rule of thumb: in the DXL manual read closely the syntax chapter and stick to whatever is in there. Some things like "pointers" while not described in the DXL manual tend to work good but are almost useless if you are not doing memory manipulation for some kind of hack (except the one valid usage as a redefinable reference). Other things like overloading the "->" operator work, but can break other non documented features like the DxlObject syntax.

In short: In the end you will do try and error and you will spend hours of debugging the more unconventional stuff you try to do in DXL.

Re: DXL Function Overload: Unassigned Variable
JoelKuehner - Sat Aug 20 09:12:44 EDT 2016

Mathias Mamsch - Sat Aug 20 05:23:38 EDT 2016

People tend to forget that DXL and C while having a similar syntax are very different from another. I do not know how else people would get the idea to declare "void" parameters, but void is not a type in DXL. Therefore you must not use it for parameters, except as the return value of a function parameter

void myFunc (void callback(int, string))  { ... }

That programs using "void" as a parameter still translate correctly is a misbehaviour of the DXL parser. There are lots of problems like this and most of them are mentioned on the forum. If you search for parser problem or parser error you will likely get some results.

As a rule of thumb: in the DXL manual read closely the syntax chapter and stick to whatever is in there. Some things like "pointers" while not described in the DXL manual tend to work good but are almost useless if you are not doing memory manipulation for some kind of hack (except the one valid usage as a redefinable reference). Other things like overloading the "->" operator work, but can break other non documented features like the DxlObject syntax.

In short: In the end you will do try and error and you will spend hours of debugging the more unconventional stuff you try to do in DXL.

Hi Mathias.

Thank you for the explanation. I have used (void) parameter lists in a lot of DXL scripts/libraries and have never been bitten before. I had no idea that it was not correct syntax. Sounds like I should over time migrate them to use () instead. As to where I got the idea to use a void parameter list, probably I just did/do it out of habit from C and, since it typically works, have never given it any thought.

I guess I never thought of a "void" parameter list as a declaration of a "void" parameter. In C, I don't think of void as a type, but rather as an indication of "nothing". So a "void" return declaration means nothing is returned, and a "void" parameter list declaration means nothing is passed in. And even a void pointer is a pointer to no particular type (vs a pointer to something with type "void").

I have always followed your advice regarding "->" overloading (I don't do it  :) ).

Thanks again for taking the time to explain.

- Joel