From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Baloff Newsgroups: gmane.emacs.help Subject: programing error Date: 28 Aug 2005 09:46:31 +1000 Organization: iPrimus Customer - reports relating to abuse should be sent to abuse@iprimus.com.au Message-ID: <8764treyeg.fsf@wash.edu> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1125185234 24538 80.91.229.2 (27 Aug 2005 23:27:14 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 27 Aug 2005 23:27:14 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Aug 28 01:27:12 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1E9A3x-00016K-IL for geh-help-gnu-emacs@m.gmane.org; Sun, 28 Aug 2005 01:26:13 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1E9A7x-0008KK-P4 for geh-help-gnu-emacs@m.gmane.org; Sat, 27 Aug 2005 19:30:21 -0400 Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 X-Original-NNTP-Posting-Host: 210.50.177.94 X-Original-NNTP-Posting-Host: 127.0.0.1 Original-Lines: 125 Original-NNTP-Posting-Host: 203.134.67.67 Original-X-Trace: 1125184933 un-2park-reader-02.sydney.pipenetworks.com.au 15514 203.134.67.67:1051 Original-X-Complaints-To: Abuse, including message IDs to abuse@pipenetworks.com Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!newsfeed.news.ucla.edu!newsfeed.media.kyoto-u.ac.jp!news1.optus.net.au!optus!news.uwa.edu.au!nntp.waia.asn.au!203.16.214.244.MISMATCH!duster.adelaide.on.net!token.pipenetworks.com!218.100.2.58.MISMATCH!not-for-mail Original-Xref: shelby.stanford.edu gnu.emacs.help:133504 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:29039 Archived-At: Hello coding in C++, I have a linked list to store int, but when I store double it is not working and I tried to find out why but could not, thanks for looking at this problem output************************************************************ @debian:~/Exercies/ThinkingInC++/Vol1/4thCh/7$ ./proj1 dblStash.fetch(0) = 0 dblStash.fetch(1) = 1 dblStash.fetch(2) = 2 dblStash.fetch(3) = 3 dblStash.fetch(4) = 4 freeing storage @debian:~/Exercies/ThinkingInC++/Vol1/4thCh/7$ ./proj1 dblStash.fetch(0) = 1.6976e-313 dblStash.fetch(1) = 1.6976e-313 dblStash.fetch(2) = 1.6976e-313 dblStash.fetch(3) = 1.6976e-313 dblStash.fetch(4) = 1.6976e-313 freeing storage @debian:~/Exercies/ThinkingInC++/Vol1/4thCh/7$ for a linked list to store int, change 'double' to 'int' in the lines marked (1) and (2) below //main.cpp************************************************** #include "stash.h" #include #include using namespace std; int main() { Stash dblStash; dblStash.initialize(sizeof(double)); // (1) for(int i = 0; i < 5; i++) dblStash.add(&i); for(int j = 0; j < dblStash.count(); j++) cout << "dblStash.fetch(" << j << ") = " << *(double*)dblStash.fetch(j) // (2) < #include using namespace std; const int increment = 5; void Stash::initialize(int sz){ size = sz; quantity = 0; next = 0; storage = 0; } int Stash::add(const void* element){ if(next >= quantity) //Enough space left? inflate(increment); // Copy element into storage, //starting at next empty space; int startBytes = next * size; //now lets copy byte-by-byte unsigned char* e = (unsigned char*)element; for(int i = 0; i < size; i++) storage[startBytes + i] = e[i]; next++; return(next -1); } void* Stash::fetch(int index){ assert(0 <= index); if(index >= next) return 0; //to indicate the end return &(storage[index * size]); } int Stash::count() { return next; } void Stash::inflate(int increase) { assert(increase > 0); int newQuantity = quantity + increase; int newBytes = newQuantity * size; int oldBytes = quantity * size; unsigned char* b = new unsigned char[newBytes]; for(int i = 0; i