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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:29:24+00:00 2026-06-14T00:29:24+00:00

Suppose you have a C++ class Foo, and you say: Foo* foos = new

  • 0

Suppose you have a C++ class Foo, and you say:

Foo* foos = new Foo[SOME_CONSTANT];
memset(foos, 0, sizeof(Foo)*SOME_CONSTANT);
//or the bzero equivalent

and that Foo has a data member Bar* barPtr. Will the above operation guarantee that
barPtr will be NULL? (i.e. zero). I ran into a case in gdb where this didn’t hold for memset and I’m curious why.

I know the above is probably bad practice but I’m asking for curiosity.

I realized that I had an extra , i was doing sizeof(Foo)*SOME_CONSTANT in the memset…

  • 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-14T00:29:26+00:00Added an answer on June 14, 2026 at 12:29 am

    On the one hand, it is implementation-defined. memset or bzero will fill the pointer value with all-zero bit pattern, which is not guaranteed to be a physical representation of null pointer on the given platform. It is not even guaranteed to produce a valid pointer value, meaning that you might end up with so called trap representation, which triggers undefined behavior when accessed.

    On the other hand, bzero is (or used to be) a part of POSIX specification. If memory serves, POSIX requires (or at least used to require) null-pointers to be represented by all-zero bit pattern, meaning that on POSIX systems it will indeed set a pointer to null.

    But again, the guarantee given by POSIX is just an example of an implementation-specific property mentioned in the first part of my answer. The language (C or C++) provides no such guarantees.

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

Sidebar

Related Questions

Suppose I have a class Baz that inherits from classes Foo and Bar ,
Suppose that I have following class template<unsigned char B, unsigned char F> class Foo
Suppose we have a class function like so: class foo { // Private data
Suppose I have the following class Foo, that supports a function of any arity
Suppose I have singleton class that acts as a data cache. Multiple threads will
Suppose I have the following: public class Foo { private ReadingList mReadingList = new
Suppose that I have class Foo and class FooFrobber { private Foo _foo; FooFrobber(Foo
Suppose I have class Foo(db.Model): bar = db.ReferenceProperty(Bar) foo = Foo.all().get() Is there a
Suppose I have: class Foo { ... }; class Bar : public Foo {
Suppose I have: class Foo { public String Bar { get; set; } }

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.