Thread: Can someone make sense of this memset for me?

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    115

    Can someone make sense of this memset for me?

    memset((char *) &ordr_mstr,'\0',sizeof(struct ordr_mstr_));

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    ordr_mstr is being set to all zeros.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by King Mir View Post
    ordr_mstr is being set to all zeros.
    And the cast to (char *) is pointless... memset() is already declared to take a void *, which can be implicitly converted from any other pointer type.

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    58
    If the structure has non-numeric fields, then they'll be set to nulls, not zeros.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    '\0' == 0 anyway, so the theory is correct (although I don't know if this applies to all systems).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,663
    > If the structure has non-numeric fields, then they'll be set to nulls, not zeros.
    Wrong way round.
    All bits zero does NOT infer a NULL pointer, or a 0.0 floating point constant.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    '\0' == 0

    You can say that without watching your wording, Elysia. Its actually more of a syntax issue than anything. I guess its considered more human readable. Though for some reason here people will debate to the bitter end the merit of using '\0'.

  8. #8
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by Elysia View Post
    '\0' == 0 anyway, so the theory is correct (although I don't know if this applies to all systems).
    Actually, no! The conversion from int to char is implementation defined.

  9. #9
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Win32 Common Controls in C++, how do i make and use them?
    By C+noob in forum Windows Programming
    Replies: 6
    Last Post: 01-09-2006, 11:53 AM
  2. Does this even remotely make sense
    By hckr83 in forum C Programming
    Replies: 6
    Last Post: 12-23-2005, 05:02 PM
  3. Simple Question on Correct Usage of memset
    By deadpoet in forum C++ Programming
    Replies: 2
    Last Post: 03-16-2004, 08:58 AM
  4. WinXP Upgrade Doesn't Make Any Sense
    By Troll_King in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 10-25-2001, 04:18 PM
  5. anyone make any sense of this
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 10-03-2001, 10:29 PM