0

ef_vi_alloc_from_pd function from this c code accepts enum as last argument:

int ef_vi_alloc_from_pd(ef_vi* vi, ef_driver_handle vi_dh,
            struct ef_pd* pd, ef_driver_handle pd_dh,
            int evq_capacity, int rxq_capacity, int txq_capacity,
            ef_vi* evq_opt, ef_driver_handle evq_dh,
            enum ef_vi_flags flags)

In this c example we define flags as unsigned vi_flags and it works:

  unsigned vi_flags;
  vi_flags = EF_VI_FLAGS_DEFAULT;
  if( cfg_timestamping )
    vi_flags |= EF_VI_RX_TIMESTAMPS;
  TRY(ef_vi_alloc_from_pd(&res->vi, res->dh, &res->pd, res->dh,
                          -1, -1, 0, NULL, -1, vi_flags));

But in c++ it doesn't work, I have compile error when calling ef_vi_alloc_from_pd error: invalid conversion from ‘unsigned int’ to ‘ef_vi_flags’ [-fpermissive]

I've tried to define vi_flags as enum:

enum ef_vi_flags vi_flags;
vi_flags = EF_VI_FLAGS_DEFAULT;
vi_flags |= EF_VI_RX_TIMESTAMPS;

But this doesn't compile too, when I doing "|=" error: invalid conversion from ‘int’ to ‘ef_vi_flags’ [-fpermissive]

How to use ef_vi_alloc_from_pd from c++?

  • how to declare vi_flags and how to call ef_vi_alloc_from_pd?
  • how to "|=" vi_flags?
  • add any options to compiler?
1
  • use a cast when? when I modify flags or when I call function? how to declare vi_flags? Commented Sep 19, 2016 at 9:29

1 Answer 1

2

You may do:

ef_vi_flags vi_flags = ef_vi_flags(EF_VI_FLAGS_DEFAULT | EF_VI_RX_TIMESTAMPS);
Sign up to request clarification or add additional context in comments.

6 Comments

i have such compile error expected ‘;’ before ‘vi_flags’ ef_vi_flags vi_flags = ef_vi_flags(EF_VI_FLAGS_DEFAULT | EF_VI_RX_TIMESTAMPS);. tried to use enum ef_vi_flags vi_flags =... and compile error again cannot convert ‘ef_vi_flags’ to ‘ef_vi*’ for argument ‘1’ to ‘ef_vi_flags ef_vi_flags(ef_vi*)’ enum ef_vi_flags vi_flags = ef_vi_flags(EF_VI_FLAGS_DEFAULT);
Have you enum ef_vi_flags defined somewhere ?
of course, for example enum ef_vi_flags vi_flags = EF_VI_FLAGS_DEFAULT; compiles just fine
@javapowered: Does ef_vi_flags vi_flags = EF_VI_FLAGS_DEFAULT; compile for you ? which compiler do you use ?
this doesn't compile error: expected ‘;’ before ‘vi_flags’ ef_vi_flags vi_flags = EF_VI_RX_TIMESTAMPS; i'm using gcc
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.