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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:38:19+00:00 2026-05-31T08:38:19+00:00

I have a unsigned c++ char buffer unsigned char* pBuffer = new unsigned char

  • 0

I have a unsigned c++ char buffer

unsigned char* pBuffer =  new unsigned char [1024];

I want to save the pBuffer pointer in the first few bytes of the newly allocated buffer by using an assignement rather than memcpy- ie

*(unsigned char*) &pBuffer[0] = pBuffer;

I am not able to get the sytax right. Appreciate help with the correct syntax for doing this.

Visual Studio 2010

  • 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-31T08:38:21+00:00Added an answer on May 31, 2026 at 8:38 am

    I don’t know why you would want to do this, but I can think of a few oddball reasons, so:

    reinterpret_cast<unsigned char**>(pBuffer)[0] = pBuffer;
    

    You want the compiler to reinterpret the pointer as a unsigned char**, and store the value of pBuffer in the 0-index slot.

    You said you’re indexing a “linked list” with multiple pBuffers. In that case, you should not use reinterpret_cast. Instead:

    struct node {
         node* prev;
         std::unique_ptr<node> next;
         unsigned char buffer[1024];
         node(node* prev_) : prev(prev_) {}
    };
    
    std::unique_ptr<node> list(new node(nullptr)); //tada
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a unsigned char pointer which contains a structure.Now I want to do
I have a unsigned char pointer which contains a structure.Now I want to do
I have the following code; void* buffer = operator new(100); unsigned char* etherhead =
I have unsigned char* , want to convert it to std::string . Can you
I have a incoming stream of bytes (unsigned char) from either a file or
I have the following code: tmp_data = simulated_data[index_data]; unsigned char *dem_content_buff; dem_content_buff = new
I have a binary array char buffer[N]; which contains two bytes to be interpreted
So far, I have this code sample: ... int nbytes =0; vector<unsigned char> buffer;
I have a unsigned char buffer, and I'm wondering how I would write and
I have this buffer given: unsigned char *buffer; int buffer_length; This is how I

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.