Article View: comp.sys.mac
Article #13746Aztec 'C' Bug Discovered
From: Rajiv Arora
Date: Sun, 07 Dec 1986 19:52
Date: Sun, 07 Dec 1986 19:52
58 lines
2867 bytes
2867 bytes
A few days ago I posted a problem I was having making certain
Appletalk Manager calls from my 'C' program. In particular, I was
trying to call the function LAPOpenProtocol and having no success. I
didn't receive any replies to my query - our news link was broken for
a few days - but I did manage to get through to Manx Tech. Support over
the phone. Turns out there's a bug in the way they handle Pascal data
types that are defined as subrange types. Just in case some of you run
into the same problem, here's a quick and dirty fix:
The function LAPOpenProtocol is defined in IM as
FUNCTION LAOpenProtocol (theLAPType: ABByte; protoptr: Ptr): OSErr
The Pascal definition of ABByte is
type ABByte = 1..127;
and the corresponding Aztec 'C' definition is
typedef unsigned char ABByte;
According to the Manx people, who, by the way, were very helpful, the
Pascal calling convention that Apple uses expects variables declared as
type ABByte to be 2 bytes long with the value contained in the HIGH
byte. The current Aztec implementation places the value in the LOW
byte and hence the problem.
The fix is to do the following:
theLAPTye = 73; /* arbitrary protocol number */
protoptr = NULL; /* install default protocol handler */
errcode = LAPOpenProtocol (theLAPType<<8, protoptr);
I checked this, and it does solve the problem. However, I suspect that
this problem may arise in many other Toolbox routines that use
variables declared as subrange types. My suspicions were confirmed to
some extent when I tried to call another Appletalk function,
DDPOpenSocket. The definition in IM is:
FUNCTION DDPOpenSocket (VAR theSocket: Byte; sktListener: Ptr): OSErr
type Byte = 0..255;
The Aztec definition of Byte is
typedef unsigned char Byte;
This function didn't work either, but in the course of my
experimentation I stumbled upon a fix: declare theSocket as type short
rather than Byte. I don't really know why this works, though!
Anyway, enough rambling. I just wanted people to be aware of the
problem in version 1.06H1 of Aztec 'C' so they don't trash their
brains. Isn't Mac programming fun? :-)
Rajiv Arora
--
UUCP: {seismo,cmc12,columbia,cornell,harvard,
ll-xn,nike,topaz}!rochester!ur-valhalla!rajiv
ARPA: ur-valhalla!rajiv@rochester.arpa
Technical Details
Message-ID:
<875@ur-valhalla.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!rochester!ur-tut!ur-valhalla!rajivShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!rochester!ur-tut!ur-valhalla!rajiv From: rajiv@ur-valhalla.UUCP (Rajiv Arora) Newsgroups: comp.sys.mac Subject: Aztec 'C' Bug Discovered Message-ID: <875@ur-valhalla.UUCP> Date: Sun, 7-Dec-86 14:52:59 EST Article-I.D.: ur-valha.875 Posted: Sun Dec 7 14:52:59 1986 Date-Received: Mon, 8-Dec-86 21:34:21 EST Reply-To: rajiv@ur-valhalla.UUCP (Rajiv Arora) Distribution: world Organization: EE VLSI Graduate Research Facility, UR, Rochester NY Lines: 58