🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #905

C question (memory allocation and access)

#905
From: Mark A. Hampson
Date: Tue, 07 Nov 1989 01:45
35 lines
1619 bytes
I have a question that I have not been able to find an answer that I feel 
comfortable with regarding the following situation:

I am attempting to allocate a block of memory as follows:

int   m = 10;
int   n = 10;
void *block;
int   block_siz;

block_siz = 2*sizeof(int) + m*n*sizeof(double);
block = malloc(block_siz);

simple enough...

I now wish to put two integers at the begining of this block of memory:

block = m;
(block+sizeof(int)) = n;   <---  here is where I am running into probs.

My intention is to store m in the first int sized space in block and to 
store n in the int sized space after it.

The compiler that I am using tells me that it does not know the size of 
block and therefore cannot perform the operation block+sizeof(int).  This
makes some sence as block is of type void *.  That being the case, how can 
I perform the operation that I want to?

Thanks in advance:
Mark A. Hampson

-- 
/----------------------------------------------------------------------------\
|      We are not in an energy crisis, we are having an entropy crisis...    |
\----------------------------------------------------------------------------/
Technical Details
Message-ID: <5322@wpi.wpi.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!usc!snorkelwacker!spdcc!merk!xylogics!cloud9!jjmhome!m2c!wpi!mhampson

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!usc!snorkelwacker!spdcc!merk!xylogics!cloud9!jjmhome!m2c!wpi!mhampson
From: mhampson@wpi.wpi.edu (Mark A. Hampson)
Newsgroups: comp.std.c
Subject: C question (memory allocation and access)
Keywords: memory access
Message-ID: <5322@wpi.wpi.edu>
Date: 7 Nov 89 01:45:53 GMT
Distribution: usa
Organization: WPI Department of Mechanical Engineering
Lines: 35