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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:23:35+00:00 2026-05-14T18:23:35+00:00

I have another memset question. It appears as if the code I am editing

  • 0

I have another memset question. It appears as if the code I am editing may have some issues (or it’s not done the same way in different files)

A::LRM las[9]; //A and LRM are both structures with BOOLS and INTS
memset(&las, 0, sizeof(las));

typedef Sec SecArray[16];
SecArray rad_array;
memset(rad_array, 0, sizeof(SecArray));

The second example appears to be correct because rad_array is the same as the first position in the array. Then the sizeof(SecArray)) would make sense. The first one doesn’t seem correct to me. All structs are just BOOLs and INTS nothing dynamic in them.

My understanding from my other post about memset was that it followed this format.

memset("pointer to object", "what to set it to", "size of object")

Can anyone tell me what exactly is going on here if I am incorrect with my theory.

  • 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-14T18:23:36+00:00Added an answer on May 14, 2026 at 6:23 pm

    Both calls to memset are correct. Both sizeof(las) (or just sizeof las) and sizeof(SecArray) will return the size of the entire array.

    If you are worried about the first argument, then again, both will work. The pointer to the entire array (&las) or the pointer to the first element (rad_array in this context) will work equally well with memset.

    In general, with regard to sizeof usage, I would recommend using the first approach, since it is type-independent. A good programming practice is to avoid mentioning type names in your statements, i.e. keep type names restricted to declarations as much as possible.

    As for the first argument, in case of an array it is a matter of preference, but in general I would say that if you have an object of type T

    T t;
    

    and you want to fill it with zeros by using memset, you’d normally do it as

    memset(&t, 0, sizeof t);
    

    I don’t see why an array should be an exception from that rule (especially if the exact nature of the type is hidden behind a typedef-name). The above memset(&t, ... will work regardless of whether T is an array type, a struct type or any other type. I don’t see why one should suddenly drop the & just because T is an array type. Quite the opposite, I’d keep that & to keep the code as type-independent as possible.

    Finally, in C++ in both cases the better way to do it would be not to use memset at all and just do

    A::LRM las[9] = {};
    SecArray rad_array = {};
    

    instead.

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

Sidebar

Ask A Question

Stats

  • Questions 405k
  • Answers 405k
  • 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 In the past I would use something like to following… May 15, 2026 at 5:49 am
  • Editorial Team
    Editorial Team added an answer I assume you're calling your extension method like this: List<MyStruct>… May 15, 2026 at 5:49 am
  • Editorial Team
    Editorial Team added an answer Since the feed is already failing... do a string replace… May 15, 2026 at 5:49 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

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.