rajiv@ur-valhalla.UUCP (Rajiv Arora) (12/07/86)
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