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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:53:12+00:00 2026-06-08T13:53:12+00:00

I have a query about using memset and memcopy on structures and their reliablity.

  • 0

I have a query about using memset and memcopy on structures and their reliablity. For eg:

I have a code looks like this

typedef struct
    {
    short a[10];
    short b[10];
}tDataStruct;

 tDataStruct m,n;

memset(&m, 2, sizeof(m));
memcpy(&n,&m,sizeof(m));

My question is,

1): in memset if i set to 0 it is fine. But when setting 2 i get m.a and m.b as 514 instead of 2. When I make them as char instead of short it is fine. Does it mean we cannot use memset for any initialization other than 0? Is it a limitation on short for eg

2): Is it reliable to do memcopy between two structures above of type short. I have a huge
strings of a,b,c,d,e… I need to make sure copy is perfect one to one.

3): Am I better off using memset and memcopy on individual arrays rather than collecting in a structure as above?

One more query,

In the structue above i have array of variables. But if I am passed pointer to these arrays
and I want to collect these pointers in a structure

typedef struct
    {
    short *pa[10];
    short *pb[10];
}tDataStruct;

 tDataStruct m,n;

memset(&m, 2, sizeof(m));
memcpy(&n,&m,sizeof(m));

In this case if i or memset of memcopy it only changes the address rather than value. How do i change the values instead? Is the prototype wrong?

Please suggest. Your inputs are very imp

Thanks
dsp guy

  • 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-08T13:53:15+00:00Added an answer on June 8, 2026 at 1:53 pm
    1. memset set’s bytes, not shorts. always. 514 = (256*2) + (1*2)… 2s appearing on byte boundaries.
      1.a. This does, admittedly, lessen it’s usefulness for purposes such as you’re trying to do (array fill).
    2. reliable as long as both structs are of the same type. Just to be clear, these structures are NOT of “type short” as you suggest.
    3. if I understand your question, I don’t believe it matters as long as they are of the same type.

    Just remember, these are byte level operations, nothing more, nothing less. See also this.

    For the second part of your question, try

    memset(m.pa, 0, sizeof(*(m.pa));
    memset(m.pb, 0, sizeof(*(m.pb));

    Note two operations to copy from two different addresses (m.pa, m.pb are effectively addresses as you recognized). Note also the sizeof: not sizeof the references, but sizeof what’s being referenced. Similarly for memcopy.

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

Sidebar

Related Questions

I would like to ask something about query using mysql I have this table
I have a L2S query that looks like this: using (MyDC TheDC = new
I have some query about my code, I am using VB6.0 and I have
HI, I have this query about smart pointers. I heard from one of my
I'm always confusing about this stuff. I have this query : string[] names =
I have query to show the table like this: but I want to PIVOT
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
I have this SQL query about getting the 5 events today: SELECT n.nid, n.type,
I have a question about using form_dropdown() . The code below works, but i
I have a query that contains about 10 joins. Using a List View and

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.