🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #53095

Help with passing union to functions..

#53095
From: Surendar chandra
Date: Tue, 17 Mar 1992 19:37
60 lines
1903 bytes
I'm trying to pass a union to a function as argument and seem to be
getting vague results. . Can you please help me out.. Thanks
surendar

============================SOURCE===========================
#include <stdio.h>

union semun {
	int val;
	char *ptr;
};

main()
{
	union semun new;

	new.val = 1;
	callf(new);
	callp(&new);
	callf(&new);
	callp(new);
}

callf(a)
union semun a;
{
	printf("%x %d %d\n",a,a.val,a.ptr);
}

callp(a)
union semun *a;
{
	printf("%x %d %d\n",a,a->val,a->ptr);
}
========================================================
If I run this in gcc 1.39 on a Multimax I get
1 1 1
ffffe908 1 1
ffffe908 -5880 -5880
1 3074560 3074560
If I run this in gcc 1.39 in a Sun SPARC station I get
Bus error
but when I run it with gcc 2.0 or with SUN OS C compiler I get
gcc 2.0:
f7fff7cc 1 1
f7fff85c 1 1
f7fff7cc 1 1
f7fff858 1 1
Sun CC:
f7fff7f8 1 1
f7fff86c 1 1
f7fff7f8 1 1
f7fff860 1 1
============================================================
To me the old gcc (1.39) seems to be working according to my
expectation and CC in Sun seems to do wrong. Please help

surendar
PS: I Need this to access GCC 1.39 and SUN OS libraries for 
semctl() function which passes a similiar union as a parameter..
Technical Details
Message-ID: <1992Mar17.193715.1229@wpi.WPI.EDU>
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!sdd.hp.com!caen!nic.umass.edu!noc.near.net!wpi.WPI.EDU!ivy!surendar

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,1651df3992a9064e,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1992-03-17 12:30:31 PST
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!sdd.hp.com!caen!nic.umass.edu!noc.near.net!wpi.WPI.EDU!ivy!surendar
From: surendar@cs.wpi.edu (Surendar chandra)
Subject: Help with passing union to functions..
Message-ID: <1992Mar17.193715.1229@wpi.WPI.EDU>
Originator: surendar@ivy
Sender: news@wpi.WPI.EDU (News)
Nntp-Posting-Host: ivy.wpi.edu
Organization: Worcester Polytechnic Institute
Date: Tue, 17 Mar 1992 19:37:15 GMT
Lines: 60