The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
questions in memset arunkumar_mca UNIX for Dummies Questions & Answers 7 08-09-2007 09:08 AM
about memset fuction ranj@chn High Level Programming 3 01-31-2006 05:59 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 07-17-2008
Registered User
 

Join Date: Apr 2006
Location: Northern Virginia
Posts: 23
Not to disagree, but

I wanted to make some mention here regarding coding -

calloc() takes two parameters, a count and a size. It simply multiplies the two values, requests that much from the heap and then does a bzero() on the result, and then returns the beginning address of the array. The result is in fact no different from a malloc() of that same product followed by a bzero() other than the typing used for the calloc() call and for the variable to which it's return value is stored. The size value can be anything from a "char" (one byte), an int (like four bytes on a 32bit machine), or a structure (size specific to the struct declaration). Sometimes used for what we used to call a "dope vector", that is, the address of the start of an array of addresses, for example. like this:
char **cpp = (char **) calloc( 10, sizeof(char *) );
in a very simple example. The variable "cpp" then becomes the address of an array of character pointers. Check K&R's "shell sort" as a good example of how one can use such a construct.

memset() is used to set a pre-allocated block of memory to a specific value. A very different kind of thing. Useful, but to be honest I don't use it much.

These days, C++ gives us "new" and we use constructors which may clear values. One thing to remember - if you compile a "C" program with the debug flag set, variables are set to zero, even the "automatic" ones. Remove the debug flag and the automatic values are no longer set. I saw one poor fellow loose an entire day trying to figure out why his program broke with no changes when he compiled it "in production". He had failed to initialize one of his automatic variables.

Last edited by fsahog; 07-17-2008 at 04:23 PM. Reason: To make it better
Reply With Quote
Google The UNIX and Linux Forums
Forum Sponsor
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 01:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0