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 8491251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:21:49+00:00 2026-06-10T22:21:49+00:00

I have some code which takes a packed POD structure/class and copies it into

  • 0

I have some code which takes a packed POD structure/class and copies it into a memory block.

struct A
{
   int a;
   int b;
} a;

memcpy(mymemoryblock, (void *)&a, sizeof(A));

// later I get a reply and...

memcpy((void *)&a, mymemoryblock, sizeof(A));

This is only valid for POD types of data, and what I would like to know if there is a way I can test for POD-ness. If someone accidentally adds a member function to this class, the memcpy operations become invalid, but still compilable. This leads to very difficult to detect bugs.

Is there a is_POD_type(A) function, or some other trick that can be used to detect PODness at runtime or compile time?

  • 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-10T22:21:51+00:00Added an answer on June 10, 2026 at 10:21 pm

    std::is_pod<A>::value in C++11.

    [Edit: refer to Luc’s comment above, in C++11 you don’t need the type to be POD for what you’re doing.

    For that matter you also don’t need to cast to void*, and C-style casting pointers to void* unnecessarily is a tiny bit risky, because some day you’ll cast away const by accident!]

    In C++03 there’s no standard way to do it, but Boost has its own is_pod that errs on the side of caution on compilers that don’t provide a non-standard way to find out. So it’s useful if you’re writing code where the POD special case is an optimization (you just won’t get the optimization everywhere). It’s also useful if you only care about compilers for which Boost can get an accurate answer. It’s not so good if false negatives by is_pod cause your code to give up in disgust.

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

Sidebar

Related Questions

I have some code which takes strings representing hexadecimal numbers - hex colors, actually
I have some code which takes a few minutes to process, it has to
I have some code which use 'this' pointer of class which calls this code.
I have written some code in which a small part of the code takes
I have some code (it's part of a wordpress plugin) which takes a text
I have some code which takes a short while to complete. I'd like it
I have got myself quite befuddled. I have some code which takes some images,
I have some Ruby code which takes dates on the command line in the
I have some code (which works fine) that looks something like this: int integer
I have some code which I want to document with in-body comments like so:

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.