On Fri, Oct 01, 2004 at 12:02:28PM +0200, [EMAIL PROTECTED] wrote:
> 2-barebones2.c
> #include <stdio.h>
>
> int main ()
> {
> int *x;
This line declares a name for a memory space that is supposed to be
large enough to contain an int. This is a valid C statement.
As an aside, I would be better mentioning declarations and
definitions as appropriate. There is an important difference among
declarations and definitions and it would better if I had used the
correct term here. Yet I am inclined to search for the correct term
right now. I don't remember the difference myself.
> int *y;
> int *z;
Another 2 names for 2 other memory spaces.
> *x=1; *y=3; *z=7;
Here you are trying to fill in the contents of the memory spaces you
previously assigned names for. The problem is that you haven't actually
ask to allocate the memory space. In general,
int x;
declares a name for a memory space *and* allocates that memory space.
In contrast,
int *x;
declares a name for a memory space *and doesn't* allocate that space.
One has to do it by hand. A construct like the following might be used:
if (x=(*int)malloc(sizeof int))
*x=1;
else printf(stderr, "malloc failed\n");
I won't be surprised if this block won't compile and/or run correctly.
My C is rusty and there are probably more then 3 errors in those 3
lines. Hopefully you will be able to find them by yourself.
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]