The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

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 12:08 PM
about memset fuction ranj@chn High Level Programming 3 01-31-2006 08:59 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-17-2008
fsahog fsahog is offline
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 07:23 PM.. Reason: To make it better
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0