Joe Billingsley
Joe Billingsley

Reputation: 3

Is casting possible in parameter expressions in OMNET++?

I have a fairly simple bit of code in OMNET++ that takes one parameter from the user and uses it to decide several others

network ExampleNetwork
{
    parameters:
         int k;
         int variable = (k / 2);

    ...
}

This code will build correctly but when running gives the error message:

'Cannot evaluate parameter 'test'. Cannot cast 1 from type double to integer (note: no implicit conversion from double to int)'

where '1' is the value of k/2.

It seems the way to fix this would be to explicitly cast the result of the expression to int but I cannot find any documentation that states how to do this in NED files.

Does anyone know how they are meant to be written?

I believe this was working on earlier versions of OMNET++. I'm now on version 5.4 on Ubuntu.

Upvotes: 0

Views: 571

Answers (1)

Attila
Attila

Reputation: 1493

Sorry for answering with a simple "RTFM", but this is the most effective: https://omnetpp.org/doc/omnetpp/manual/#sec:ned-functions:category-conversion

Since OMNeT++ 5.3, double values are no longer converted to int implicitly.

Use the int function, like this: int variable = int(k / 2);

Upvotes: 4

Related Questions