Xref: utzoo comp.sys.mac.hypercard:296 comp.sys.mac:11618 Path: utzoo!utgpu!water!watmath!watcgl!kdmoen From: kdmoen@watcgl.waterloo.edu (Doug Moen) Newsgroups: comp.sys.mac.hypercard,comp.sys.mac Subject: Re: HyperCard XFCNs in MPW C Message-ID: <3105@watcgl.waterloo.edu> Date: 31 Jan 88 05:06:21 GMT References: <226STORKEL@RICE> Reply-To: kdmoen@watcgl.waterloo.edu (Doug Moen) Organization: U. of Waterloo, Ontario Lines: 53 In article <226STORKEL@RICE> STORKEL@RICE.BITNET (Scott Storkel) writes: >Help! I am trying to compile a Hypercard XFCN written in MPW C. The program >compiles fine, then I try to link it using the following commands: > > link -sn Main=Bool -sn STDIO=Bool: > -sn INTENV=Bool -rt XFCN=5: > -m BOOL Boolean.c.o "{CLibraries}"CRuntime.o: > "{CLibraries}"CInterface.o: > "{CLibraries}"StdCLib.o: > "{CLibraries}"CSANELib.o: > -o HyperCommands > >When I do this, the compiler gives me the error "Data initialization code is >not being called" and terminates. The output file contains the XFCN resources >Bool=5, and also SADEV=6, SACONSOL=7, and CSANELIB=8. You can't have global variables *or character string literals* in an XFCN written in MPW C. Boy was I pissed off when I figured this out. I don't know of any reasonable workarounds, either. Some kludges for faking string literals: * You can put them into STR# resources * You can use the following C function that I invented: strlit(p, s) char *p; { strcpy(p, (char *)&s); return p; } Now you can replace character string literals like: "foobar" with: char buf[256]; ... strlit(buf, 'foob','ar\0\0'); Both kludges are really pretty awful, but I have no better ideas right now except to write a preprocessor for stripping out string literals and replacing them with something that the linker won't choke on. By the way, you can't put global variables or string literals into INITs, desk accessories, and related code resources, either. Does anybody at Apple care enough to fix this? -- Doug Moen University of Waterloo Computer Graphics Lab UUCP: {ihnp4,watmath}!watcgl!kdmoen INTERNET: kdmoen@cgl.waterloo.edu