Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6158607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:59:12+00:00 2026-05-23T20:59:12+00:00

There is the following definition in some legacy code that I am working with.

  • 0

There is the following definition in some legacy code that I am working with.

struct VlanData
{
    uint16_t mEtherType;
    uint16_t mVlanId;
};

I want to add a new member to this struct:

struct VlanData
{
    uint16_t mEtherType;
    uint16_t mVlanId;
    uint8_t mVlanPriority; // New member
};

However, use of VlanData has been fairly inconsistent through the legacy code.

Not initialized on construction:

VlanData myVlans;
myVlans.mEtherType = 0x8100;
myVlans.mVlanId = 100;

Value initialized:

VlanData myVlans = { 0x8100, 100 };

What I want to do is come up with a safe way to ensure that `mVlanPriority’ is automatically set to 0 in legacy code without updating a lot of code.

I understand I could modify the legacy code to value-initialize all members like so:

VlanData myVlans = {};

But I don’t want to have to update all of this code. I believe that creating a default constructor like this would help:

VlanData()
: mEtherType(0),
  mVlanId(0),
  mVlanPriority(0)
{}

But this would also destroy the POD-ness of the struct.

So I guess I have several questions:

  1. Is there a safe way I can ensure that mVlanPriority is set to 0 in legacy code without updating the legacy code?
  2. What use of the class would break if this was no longer a POD type?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:59:13+00:00Added an answer on May 23, 2026 at 8:59 pm
    struct VlanData {
        struct P
        {
            uint8_t operator=(uint8_t v) { mVlanPriority = v; }
            uint8_t mVlanPriority; P() { mVlanPriority = 0; };
        };
        uint16_t mEtherType;
        uint16_t mVlanId;
        P mVlanPriority;
     };
    

    Define other kinds of operators and add type conversion functions as you need.

    eg:

    int main(int argc, char** argv)
    {
        VlanData myVlans0 = { };
        VlanData myVlans = { 0x8100, 100 };
        myVlans.mVlanPriority = 10;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on some C++ code that a friend has written and I
I understand the following elements : there is some sort of crawling (configured in
I have the following situation: There is a tool that gets an XSLT from
On F# WikiBook under Encapsulating Mutable State section, there is a following code snippet.
In the jquery.cycle.js file, there is the following code: $.fn.cycle.transitions.scrollRight = function($cont, $slides, opts)
Hi there im using the following code for insert text and images, but I
I have the following: KeyValuePair<string, string>? myKVP; // code that may conditionally do something
I have a grid with the following definition. Everything is working fine with the
I'm trying to port some Visual C++ (VS2005) code so that it will compile
I have some trouble forward declaring a function that uses boost::enable_if : the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.