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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:20:22+00:00 2026-05-16T05:20:22+00:00

static int write_stream(const void *buffer, size_t size, void *app_key) { char *stream = (char

  • 0
static int write_stream(const void *buffer, size_t size, void *app_key) 
{
    char *stream = (char *)app_key;

    return 0;
}

Why pointer casting does
not result in a copying of (size_t size) bytes from buffer into the
stream defined by app_key?

Thanks

Edit: I’m calling this function as argument of another function to use callback :

static int write_stream(const void *buffer, size_t size, void *app_key) 
{
    char *stream = (char *)app_key; 
    return 0;
}

int print_to_2buf(char *ostream, struct asn_TYPE_descriptor_s *td, void *struct_ptr)
{
    asn_enc_rval_t er; /* Encoder return value */

    // write_stream is called as argument
    er = xer_encode
    (
        td,
        struct_ptr,
        XER_F_BASIC,
        /* BASIC-XER or CANONICAL-XER */ write_stream,
        ostream
    );

    return (er.encoded == -1) ? -1 : 0; 
}
  • 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-16T05:20:23+00:00Added an answer on May 16, 2026 at 5:20 am

    From your question, I can’t be certain your level of understanding, but it looks as though you are not familiar with the mechanics of pointers, so I will try to give a quick explanation.

    Your parameter void *app_key is an integer that stores the location in memory of a block of unknown (void) type.

    Your char *stream is also an integer, it stores the location in memory of a block of char type (either a single char or the first char in a continuous block).

    Your line of code char *stream = (char *)app_key copies the integer value of app_key (that is, the address in memory that app_key refers to), and stores it also in stream.

    At this point, both app_key and stream store the same location in memory — the address of the first character in your app_key (assuming that a string was passed as the parameter).

    Realize, however, that the only thing that was copied was the integer memory address of your app_key. There is still only one copy.

    What it sounds like you wanted to do was to make an entire new copy of the app_key string, one that was stored in a different location in memory (perhaps so that when the function returns and the original string is destroyed you still have your copy).

    In order to do that, you need to do the following:

    1: allocate memory space sufficient to hold the new copy
    2: copy all of the characters from the original to the copy
    

    There are many ways to do this depending on what your needs are. Here is one:

    
    static int 
    write_stream (const void *buffer, size_t size, void *app_key) 
    {
        //create a memory buffer large enough to hold size_t size chars.
        char *stream = (char *)malloc(sizeof(char) * size);
    
        //copy size_t size chars from location at app_key to location at stream
        memcpy(stream, app_key, sizeof(char) * size);
    
        //rest of your function
    }
    

    Because you are working with strings, you could also make use of the strcpy() function (potentially paired with strlen). Those functions all assume that you are using a NULL-terminated string (that is, the string is a sequence of chars, with a final \0 at the end to indicate the end.

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

Sidebar

Ask A Question

Stats

  • Questions 497k
  • Answers 497k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I really, really doubt this is a virus. Double-check whether… May 16, 2026 at 11:50 am
  • Editorial Team
    Editorial Team added an answer Should I care at all? Should I just use the… May 16, 2026 at 11:50 am
  • Editorial Team
    Editorial Team added an answer You need to connect as SYS (or equivalent privileges) and… May 16, 2026 at 11:50 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have an Array like: private static int[] f_arme = { R.drawable.frankiearmevor_0001, R.drawable.frankiearmevor_0002, R.drawable.frankiearmevor_0003,
Trying to create an app that does some socket communication (Writing only). I can
I'm trying to write a method to take a multiline tab-delimited file and return
I am trying to define a public static variable like this : public :
I dont get it. I have used a similar/same approach for many years now,
I have to pass the path of a config file to a framework method
A lot of items I've found so far have been a bit vague or
I have a problem with boost shared_memory_object and mapped_region. I want to write a
NetFoss requires you to run it with a command line similar to this: nf.bat
I'm a fairly new programmer so please bear with me on this. I am

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.