[comp.unix.questions] void *a

kyriazis@rpics (George Kyriazis) (05/30/89)

OK.  Here is the program..

struct	a	{
		void	*pt;
	} foo;


main()
{
	foo.pt = (void *) &foo;
}

The compiler complains that 'pt' is not defined, on ANY system I tried
it except the SUN.  What's so special about suns and/or void *  ???

Am I missing something??  By void * I mean some generic kind of pointer.


  George Kyriazis
  kyriazis@turing.cs.rpi.edu
  kyriazis@rdrc.rpi.edu
------------------------------

gwyn@smoke.BRL.MIL (Doug Gwyn) (05/30/89)

In article <5197@rpi.edu> kyriazis@turing.cs.rpi.edu (George Kyriazis) writes:
>Am I missing something??  By void * I mean some generic kind of pointer.

What you're missing is that void* is a fairly recent innovation,
and many existing UNIX C compilers don't yet support it.

ark@alice.UUCP (Andrew Koenig) (05/30/89)

In article <5197@rpi.edu>, kyriazis@rpics (George Kyriazis) writes:

	struct	a	{
			void	*pt;
		} foo;

	main()
	{
		foo.pt = (void *) &foo;
	}

> The compiler complains that 'pt' is not defined, on ANY system I tried
> it except the SUN.  What's so special about suns and/or void *  ???

It works fine here.  Are you sure you transcribed it correctly
on those other machines?  I don't see anything obviously wrong.
-- 
				--Andrew Koenig
				  ark@europa.att.com

sandy@conexch.UUCP (Sandford Zelkovitz) (05/31/89)

In article <5197@rpi.edu>, kyriazis@rpics (George Kyriazis) writes:
> 
> OK.  Here is the program..
> struct	a	{
> 		void	*pt;
> 	} foo;
> main()
> {
> 	foo.pt = (void *) &foo;
> }
> The compiler complains that 'pt' is not defined, on ANY system I tried
> it except the SUN.  What's so special about suns and/or void *  ???





I compiled your example under Xenix386 without any complaints from the
compiler. 
 
Sanford <sandy> Zelkovitz
XBBS  714-898-8634

chris@mimsy.UUCP (Chris Torek) (05/31/89)

In article <5197@rpi.edu> kyriazis@rpics (George Kyriazis) writes:
>	void	*pt;
>... The compiler complains that 'pt' is not defined, on ANY system I tried
>it except the SUN.  What's so special about suns and/or void *  ???

The systems you tried must be using a version of PCC (`Portable C
Compiler').  PCC, like many compilers for many languages, keeps track
not only of declared variables but also of undeclared variables, and
emits an error only on the first use:

	main() {
		i = 10;	/* gets an error */
		i++;	/* says nothing */
		j++;	/* gets an error */
		j = i;	/* says nothing */
	}

Through some oversight, when `void' was added to PCC, someone used a
type-code number that, combined with `pointer to', matched the special
value for `undeclared variable': `void *p' enters p into the symbol
table as a `complain about this undeclared variable' name.%

This bug is fixed in modern PCCs, including the ones on current Berkeley
tapes.
-----
% This is not exactly right, but is close enough for explanatory purposes....
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris