Another C compiler bug

tan_j at wums2.wustl.edu tan_j at wums2.wustl.edu
Wed Jul 18 16:18:55 AEST 1990


>> item 1985
>> Is it a bug or not? I can compile the piece of program below successfully 
>> on Sun 3/60(4.0_Export), HP900/825(7.00). But I failed to do that on 4D 20 
>> under IRIX 3.2.

struct Alist_Entry    {
    void *slot;
} ;
main()
{
	register struct Alist_Entry *ap;
	*( (int *) (ap->slot) ) = 11;
	*((char *)(ap->slot)) = 'a';
}
=======================================================================
If you read the SGI C Language reference manual on operator conversions
(section 4.7 on Version 1.0 manual), it reads:
The (nonexistent) value of a object may not be used in any way, and
neither explicit nor implicit conversion may be applied. 
...... etc....

and section 3.2 on Type,

The void type specifies an empty set of values.  It is used as the type 
returned by functions that generate no value.

Which means SGI C compiler does not allow void type usage as on other systems.
=======================================================================
You may want to check your C code also.  This is a common mistake.
Suppose void type is accepted on SGI, 
*( (int *) (ap->slot) ) = 11
will type cast ap->slot into an integer pointer, then change the content
that is pointed by ap->slot to 11, not the ap->slot.  So where is your
initialization of ap->slot ?  It is NULL !! Declaring a pointer does
not allocate a 'real' (you know what I mean) space.
What you want probably is declare another variable, NOT pointer,

      register struct Alist_Entry *ap, temp;
      ap=&temp;
      
Then it will be fine.

"SGI newcomer"
tan_j at wums.stl.edu
Washington University Medical School



More information about the Comp.sys.sgi mailing list