[comp.sys.sgi] C Error on 4d/25 TGX, irix 3.2.1

baugh@potomac.ads.com (Earl Baugh) (07/12/90)

Ok, I'm totally confused here...In the following code segment, 
why do I get the error messages that follow....why undefined p1 & p2?
I tried compiling the same source on a Sun (4.0.3) [though I had to 
change the prototype to the old style declaration] and two 
PC compilers and none of them had any problems, so why a problem
with the iris?  (I tried changing the prototype to an old style 
declaration and still had the same problem)

If there is some "C" knowledge I'm missing here, I'd like to 
know where to find out about it.....

---------------------------------Code test.c -------------------------------

#include <stdio.h>
#define TYPETABLESIZE 255

int  TypeHash(int code, void *p1, void *p2);

int  TypeHash (int code, void *p1, void *p2) 
{
     return (int) abs(((code * abs(((long)*p1+1)) * abs(((long)*p2+1))) % TYPETABLESIZE)) + 1;

} 

main()
{
	int a, b, c;

	a = 1;
	b = 2;
	c = 3;

  	TypeHash(a, (void *)&b, (void *)&c);  
}
-------------------------results of "make test"-----------------------------

	cc -O test.c  -o test
ccom: Error: test.c, line 8: p1 undefined
           return (int) abs(((code * abs(((long)*p1+1)) * abs(((long)*p2+1))) % 255)) + 1;
      ---------------------------------------------^
ccom: Error: test.c, line 8: illegal indirection
           return (int) abs(((code * abs(((long)*p1+1)) * abs(((long)*p2+1))) % 255)) + 1;
      ---------------------------------------------^
ccom: Error: test.c, line 8: p2 undefined
           return (int) abs(((code * abs(((long)*p1+1)) * abs(((long)*p2+1))) % 255)) + 1;
      ------------------------------------------------------------------^
ccom: Error: test.c, line 8: illegal indirection
           return (int) abs(((code * abs(((long)*p1+1)) * abs(((long)*p2+1))) % 255)) + 1;
      ------------------------------------------------------------------^
(ccom): test.c, line 8: cannot recover from earlier errors: goodbye!
      } 
      ^
*** Error code 1

Stop.
---------------------------------------------------------------------------


'Later-- 
	Earl D. Baugh Jr.
	Advanced Decision Systems
	Internet : baugh@ads.com

robert@texas.esd.sgi.com (Robert Skinner) (07/14/90)

In article <8903@potomac.ads.com>, baugh@potomac.ads.com (Earl Baugh) writes:
|> 
|> Ok, I'm totally confused here...In the following code segment, 
|> why do I get the error messages that follow....why undefined p1 & p2?
|> I tried compiling the same source on a Sun (4.0.3) [though I had to 
|> change the prototype to the old style declaration] and two 
|> PC compilers and none of them had any problems, so why a problem
|> with the iris?  (I tried changing the prototype to an old style 
|> declaration and still had the same problem)
|> 
|> If there is some "C" knowledge I'm missing here, I'd like to 
|> know where to find out about it.....
|> 
|> ---------------------------------Code test.c -------------------------------
|> 
|> #include <stdio.h>
|> #define TYPETABLESIZE 255
|> 
|> int  TypeHash(int code, void *p1, void *p2);
|> 
|> int  TypeHash (int code, void *p1, void *p2) 
|> {
|>      return (int) abs(((code * abs(((long)*p1+1)) *
abs(((long)*p2+1))) % TYPETABLESIZE)) + 1;
|> 
|> } 
|> 

I *think* its because p1 is a void*, when you say (long)*p1, you derefernce
a void* which is undefined (fetch a void?  whats a void?) then cast it to 
long.  I think you want to cast it to a long*, 
then derefernce:  *((long *)p1).

(It shouldn't matter, but it would be nice if your cast matched what you 
pass:  both ints or longs.)

Robert Skinner
robert@sgi.com

Send lawyers, guns and money. -- Warren Zevon