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

  • SEARCH
  • Home
  • 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 9125875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:54:23+00:00 2026-06-17T06:54:23+00:00

I have a set of structs which come from some C code I’m converting

  • 0

I have a set of structs which come from some C code I’m converting to C++, they should be POD types according to what I understood. Here are some examples:

struct Data {
  u16 type : 12;
  u8 variant : 3;
  bool isTop : 1;
};

struct DData {
  u16 type : 12;
  u8 variant : 3;
  u8 layer : 1;
};

struct TData {
  struct Data data1, data2;
  struct DData ddata[MAX];
  u16 x;
  u8 y;
  u8 s : 4;
  u8 l : 4;
  u8 wl : 3;
  u8 wr : 3;
  u8 lt : 2;
};

I have many methods which up to now had pointer to these structs as parameters and I was planning to move them directly inside the struct declarations to save a lot of typing, eg.

struct Data {
  u16 type : 12;
  u8 variant : 3;
  bool isTop : 1;

  inline bool hasFlag(u64 flag) { return Types::specs[type].flags & flag; }
 };

I was wondering if every method I can add in this way will be safe for this struct, these structures are serialized over the network and into binary files so I need to be sure that this can’t potentially break anything. If I’m right they should remain POD types so no particular problems or overhead should appear.

  • 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-06-17T06:54:25+00:00Added an answer on June 17, 2026 at 6:54 am

    That should remain a POD.

    You can be sure by using the std::is_pod trait:

    std::is_pod<Data>::value;
    

    will be true if Data is a POD, false otherwise.

    Anyway, I wouldn’t bother moving the functions into the struct body. You’re not really gaining anything besides a different calling syntax.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some C code embedded inside an R function which keeps sigsegging in
I'm doing this graphics project in which I have a set of points(in 3
I have some code that returns a struct containing 2 objects (declared as id
Suppose I have a number of C structs for which I would like a
I have a class which contains several structs: public class NavigationMenu { public struct
I have an array of structs, and I have some functions that will be
I have set the eclipse java formatter to wrap lines that exceed 120 characters
I have set a background on the data-role=page element like so <div data-role=page style=background:
I have set up Eclipse Indigo to do line debugging with CFEclipse over port
I have set up upload_max_filesize and post_max_size to 32Mb in php.ini. I am using

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.