Home Bug Reports

default vaules in Slice

denndenn Member Denn SporcicOrganization: L3 NautronixProject: Great Barrier Reef Vessel Tracking System
Hi Guys,

Testing my code with Ice 3.4.2 and noticed a change in generated code with regards to initializer lists in C++.

It's to do with float default values.
Example SLICE

class aClass
{
float a = 0.0;
float b = 1.1;
double c = 0.0;
double d = 1.1;
};

This used to generate

::aClass::aClass() :
a(0),
b(1.1),
c(0),
d(1.1)

Now it generates

::aClass::aClass() :
a(0F),
b(1.1F),
c(0),
d(1.1)

GCC and Visual Studio is now complaining about variable 'a' with an invalid suffix 'F'.

Having 'F' is more correct, however the parser should not be truncating default values for floats and doubles.

(float a = 0F) != (float a = 0.0F)

My only work around is not to set a default value of 0.0 anymore. Or hack the cpp/src/slice2cpp/Gen.cpp line 107 and remove the 'F' suffix.


VERY annoying..!

cheers
Denn

Comments

  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Hi Deen

    as a workaround you can use a const int:
    const int zeroI = 0;
    
    struct s
    {
       float x = zeroI;
    }
    

    Thanks for report the bug, we will fix this in the next Ice release
Sign In or Register to comment.