systemc

typedef an sc_fixed but got template error


Trying to define a simple sc_fixed type in Visual Studio 2017:

#include <systemc.h>
#include <sysc/datatypes/fx/sc_fixed.h>   # just in case
....
typedef sc_fixed<16, 4> fixed_type;
....

This typedef line resulted an error:

E0864: sc_fixed is not a template

Had no idea why this error popped, even included sysc/datatypes/fx/sc_fixed.h. Why does it say "not a template"?


Solution

  • From INSTALL file shipped with SystemC

    SystemC 2.3 includes a fixed-point package that is always built. When compiling your applications with fixed-point types, you still have to use compiler flag -DSC_INCLUDE_FX. Note that compile times increase significantly when using this compiler flag.

    Using your code as an example

    #include <systemc.h>
    #include <sysc/datatypes/fx/sc_fixed.h>
    
    #include <iostream>
    
    typedef sc_dt::sc_fixed<16, 4> fixed_type;
    
    int sc_main(int, char**){
        fixed_type ft(1.25);
        std::cout << "ft = " << ft << '\n';
        return 0;
    }
    

    Gives me the output

    ft = 1.25
    

    As a caveat it is best to check the docs for your particular version of SystemC as I believe this #define may have been removed in 2.3.3 (I am using 2.3.2) I am not certain.