Weird pointer declaration bug
Philipp Thomas
pthomas@suse.de
Sun Aug 27 15:48:00 GMT 2000
* 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
More information about the Gcc-bugs
mailing list