Skip to contentSkip to conversation

"virtual" C++ keyword used in rte_devargs.h and causes compilation error in C++

DISCUSSION Ming Zhao 3 participants 5 messages Feb 7, 2015 – Feb 8, 2015 4 messages not in the archive

lore
Share & tools
lore

Ming Zhao

author
#0 lore raw

The code is in rte_devargs.h:

rte_devargs.h:

                /** Used if type is RTE_DEVTYPE_VIRTUAL. */
                struct {
                        /** Driver name. */
                        char drv_name[32];
                } virtual;
        };

Which caused clang compiler to report error when this file is included by a cpp file, the error message is:

In file included from net/dpdk/testing/base-test.cc:3:
In file included from net/dpdk/testing/base-test.h:8:
third-party/dpdk/lib/librte_eal/common/include/rte_devargs.h:89:5:
error: 'virtual' can only appear on non-static

      member functions
                } virtual;
                  ^

I think we should try to pick another name for this field. I would suggest calling it "vdev" instead, or I'll be happy to take another name if someone comes with a different idea.

Thanks!
Ming

A message that is not in the archive (sent off-list or not yet received): 54D5BD9F.7000902-82A4bShDkBpJQxFrfMEhiVaTQe2KTcn/@public.gmane.org

#2 lore raw
Quoted 22 lines · Ming Zhao

The code is in rte_devargs.h:

rte_devargs.h:

                /** Used if type is RTE_DEVTYPE_VIRTUAL. */
                struct {
                        /** Driver name. */
                        char drv_name[32];
                } virtual;
        };

Which caused clang compiler to report error when this file is included by a cpp file, the error message is:

In file included from net/dpdk/testing/base-test.cc:3:
In file included from net/dpdk/testing/base-test.h:8:
third-party/dpdk/lib/librte_eal/common/include/rte_devargs.h:89:5:
error: 'virtual' can only appear on non-static

      member functions
                } virtual;
                  ^
Quoted 7 lines

I think we should try to pick another name for this field. I would suggest calling it "vdev" instead, or I'll be happy to take another name if someone comes with a different idea.

Thanks!
Ming

You could do that, but it seems like it shouldn't be necessecary. Shouldn't the solution just be to encapsulate either the header file or the #include directive from the C++ file with extern C { }?
Neil

A message that is not in the archive (sent off-list or not yet received): 20150207202349.GA7064-0o1r3XBGOEbbgkc5XkKeNuvMHUBZFtU3YPYVAmT7z5s@public.gmane.org

author
#4 lore raw

In fact the current rte_devargs.h header is enclosed inside extern C {} block already. But it looks like it's not sufficient. Also there is also the case that rte_devargs.virtual field could be accessed inside a cpp file.

Quoted 35 lines · Neil Horman
Quoted 22 lines · Ming Zhao

The code is in rte_devargs.h:

rte_devargs.h:

                /** Used if type is RTE_DEVTYPE_VIRTUAL. */
                struct {
                        /** Driver name. */
                        char drv_name[32];
                } virtual;
        };

Which caused clang compiler to report error when this file is included by a cpp file, the error message is:

In file included from net/dpdk/testing/base-test.cc:3:
In file included from net/dpdk/testing/base-test.h:8:
third-party/dpdk/lib/librte_eal/common/include/rte_devargs.h:89:5:
error: 'virtual' can only appear on non-static

      member functions
                } virtual;
                  ^
Quoted 7 lines

I think we should try to pick another name for this field. I would suggest calling it "vdev" instead, or I'll be happy to take another name if someone comes with a different idea.

Thanks!
Ming

You could do that, but it seems like it shouldn't be necessecary. Shouldn't the solution just be to encapsulate either the header file or the #include directive from the C++ file with extern C { }?
Neil

A message that is not in the archive (sent off-list or not yet received): 54D70343.6060502-82A4bShDkBpJQxFrfMEhiVaTQe2KTcn/@public.gmane.org

#6 lore raw

"virtual" is a reserved word in c++. When the c++ compiler "g++" use that header in a "extern way (just generate standard typo for function identifiers)", there`s not way that the compiler posible "turn off" the "virtual" reserved word. If, for example, you guys use the "new" word ... its just the same as virtual.

Regards.

Quoted 44 lines · Ming Zhao

In fact the current rte_devargs.h header is enclosed inside extern C {} block already. But it looks like it's not sufficient. Also there is also the case that rte_devargs.virtual field could be accessed inside a cpp file.

Quoted 23 lines · Neil Horman
Quoted 22 lines · Ming Zhao

The code is in rte_devargs.h:

rte_devargs.h:

                /** Used if type is RTE_DEVTYPE_VIRTUAL. */
                struct {
                        /** Driver name. */
                        char drv_name[32];
                } virtual;
        };

Which caused clang compiler to report error when this file is included by a cpp file, the error message is:

In file included from net/dpdk/testing/base-test.cc:3:
In file included from net/dpdk/testing/base-test.h:8:
third-party/dpdk/lib/librte_eal/common/include/rte_devargs.h:89:5:
error: 'virtual' can only appear on non-static

      member functions
                } virtual;
                  ^
Quoted 8 lines
Quoted 7 lines

I think we should try to pick another name for this field. I would suggest calling it "vdev" instead, or I'll be happy to take another name if someone comes with a different idea.

Thanks!
Ming

You could do that, but it seems like it shouldn't be necessecary.

Shouldn't the

Quoted 1 line

solution just be to encapsulate either the header file or the #include

directive

Quoted 3 lines

from the C++ file with extern C { }?
Neil

A message that is not in the archive (sent off-list or not yet received): CADoa0baQnWJTUhJRWh13UJCcqZ_JEpd5mwzVdfPeeehJ+fLYdg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#8 lore raw
Quoted 6 lines · Ariel Rodriguez

"virtual" is a reserved word in c++. When the c++ compiler "g++" use that header in a "extern way (just generate standard typo for function identifiers)", there`s not way that the compiler posible "turn off" the "virtual" reserved word. If, for example, you guys use the "new" word ... its just the same as virtual.

Hmm, you're right, it seems the C++ specification only uses the extern "Language" construct to define linkage behavior, it in no way defines keyword recognition or behavior.

Truthfully, while this would be easy to fix by just changing the name, it might be a good oportunity to make the rte_devargs struct private. It really doesn't need to be public at all, if you had an accessor/iterator function for the list, and that would implicitly solve the problem by moving all the identifiers out of any publically accessible namespace

Neil

Quoted 49 lines

Regards.

Quoted 44 lines · Ming Zhao

In fact the current rte_devargs.h header is enclosed inside extern C {} block already. But it looks like it's not sufficient. Also there is also the case that rte_devargs.virtual field could be accessed inside a cpp file.

Quoted 23 lines · Neil Horman
Quoted 22 lines · Ming Zhao

The code is in rte_devargs.h:

rte_devargs.h:

                /** Used if type is RTE_DEVTYPE_VIRTUAL. */
                struct {
                        /** Driver name. */
                        char drv_name[32];
                } virtual;
        };

Which caused clang compiler to report error when this file is included by a cpp file, the error message is:

In file included from net/dpdk/testing/base-test.cc:3:
In file included from net/dpdk/testing/base-test.h:8:
third-party/dpdk/lib/librte_eal/common/include/rte_devargs.h:89:5:
error: 'virtual' can only appear on non-static

      member functions
                } virtual;
                  ^
Quoted 8 lines
Quoted 7 lines

I think we should try to pick another name for this field. I would suggest calling it "vdev" instead, or I'll be happy to take another name if someone comes with a different idea.

Thanks!
Ming

You could do that, but it seems like it shouldn't be necessecary.

Shouldn't the

Quoted 1 line

solution just be to encapsulate either the header file or the #include

directive

Quoted 3 lines

from the C++ file with extern C { }?
Neil