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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:41:17+00:00 2026-05-25T21:41:17+00:00

A few examples of what I’m referring to: typedef struct SOME_STRUCT { unsigned int

  • 0

A few examples of what I’m referring to:

typedef struct SOME_STRUCT {
  unsigned int x1;
  unsigned int x2;
  unsigned int x3;
  unsigned int x4;

  // What I expected would work, but doesn't; the 2nd parameter gets
  // turned into an 8-bit quantity at some point within memset
  SOME_STRUCT() { memset( this, 0xFEEDFACE, sizeof( *this ) ); }

  // Something that worked, but seems hokey/hackish
  SOME_STRUCT() {
    unsigned int *me = (unsigned int *)this;
    for( int ii = 0; ii < sizeof(*this)/sizeof(*me); ++ii ) {
      me[ii] = 0xFEEDFACE;
    }
  }

  // The far-more-verbose-but-C++-way-of-doing-it
  // This works, but doesn't lend itself very well
  // to being a drop-in way to pull this off on
  // any struct.
  SOME_STRUCT() :  x1( 0xFEEDFACE )
                 , x2( 0XFEEDFACE )
                 , x3( 0XFEEDFACE )
                 , x4( 0XFEEDFACE ) {}

  // This would work, but I figured there would be a standard
  // function that would alleviate the need to do it myself
  SOME_STRUCT() { my_memset( this, 0xFEEDFACE, sizeof(*this) ); }
}

I can’t use valgrind here, and my options are limited as far as various debugging libraries I have access to — which is why I’m doing it myself for this one-off case.

  • 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-25T21:41:18+00:00Added an answer on May 25, 2026 at 9:41 pm

    Here’s a partial example of using std::generate() safely:

    #include <algorithm>
    
    struct Wizard {
        size_t i;
        static unsigned char magic[4];
        Wizard() : i(0) {}
        unsigned char operator()() {
            size_t j = i++;
            i %= sizeof(magic); // Not strictly necessary due to wrapping.
            return magic[j];
        }
    };
    
    unsigned char Wizard::magic[4] = {0xDE,0xAD,0xBE,0xEF};
    
    std::generate(reinterpret_cast<unsigned char*>(this),
                  reinterpret_cast<unsigned char*>(this) + sizeof(*this),
                  Wizard());
    

    (Of course, the endianness may or may not be right, depending on how you’re looking and what you’re expecting to see when you do!)

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

Sidebar

Related Questions

I was playing around with Python's subprocess module, trying a few examples but I
I know what yield does, and I've seen a few examples, but I can't
A few examples: ilikestackoverflow would match i like stackoverflow thisisanotherexample would match this is
I've seen a few examples on here to this problem, but none have solved
I've read and looked a quite a few examples for Threadpooling but I just
I've seen a few examples but none so far in C#, what is the
I have begun to understand a few examples related to currying but I am
I have looked on here and found a few examples but nothing works so
Learning how to use scala DSL:s and quite a few examples work nice. However
Seems simple question but I really suck at math and few examples online I've

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.