pointer & struct

Wayne A. Throop throopw at xyzzy.UUCP
Thu Feb 9 05:38:15 AEST 1989


> dvu at pyr.gatech.EDU (Dinh Vu)
> The small program below compiled fine, but
> it gave core dump when I run it.  Would someone give me 
> some light on this matter.

In general, you should run "lint" on your programs.  It will catch
many simple errors, such as the one here.  In this instance, lint
has this to say:

    (12)  warning: var may be used before set
    (14)  warning: main() returns random value to invocation environment

about the appended program Dinh was wondering about.  It is perhaps
a little cryptic, but it covers the essentials: the struct pointer
was used before it was set to anything, and the program will
potentially return an undefined value to its invoker.

	#include <stdio.h>
	
	struct abc {
		int x;
		int y;
	};

	main()
	{
		struct abc *var;

		var->x = 5;
		var->y = 10;
	}
--
"Cogito, ergo spud."
I think, therefore a yam.
-- 
Wayne Throop      <the-known-world>!mcnc!rti!xyzzy!throopw



More information about the Comp.lang.c mailing list