This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Weird pointer declaration bug
- To: Karl-Max Wagner <karlmax at oberland dot net>
- Subject: Re: Weird pointer declaration bug
- From: Philipp Thomas <pthomas at suse dot de>
- Date: Mon, 28 Aug 2000 00:48:20 +0200
- Cc: gcc-bugs at gcc dot gnu dot org
- References: <200008272217.WAA00508@schreyer.oberland.net>
* Karl-Max Wagner (karlmax@oberland.net) [20000828 00:17]:
> It seems that none of the pointer variables declared in function
> foo are assigned proper memory space - in both cases 0x0 is
> shown as address. Subsequent attempt to assign values to them
> result in a segfault.
Wellcome to the world of C :) That's how it should be as per the standard!
You have to allocate the memory yourself. Something like:
void foo(float bar)
{
float *a;
float *b;
float c;
a = malloc(sizeof(float));
b = &c;
*a = bar;
*b = bar;
free(a);
}
For more information, visit a book about ISO C nearest to you or newsgroups
like comp.lang.c and comp.lang.c.moderated.
Philipp
--
Philipp Thomas <pthomas@suse.de>
Development, SuSE GmbH, Schanzaecker Str. 10, D-90443 Nuremberg, Germany
#define NINODE 50 /* number of in core inodes */
#define NPROC 30 /* max number of processes */
-- Version 7 UNIX for PDP 11, /usr/include/sys/param.h