🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #9348

Re: how to write reentrant C code?

#9348
From: Matt Dillon
Date: Sun, 24 Jul 1988 06:03
35 lines
1896 bytes
>   Does anybody know what the dos and don'ts are to write reentrant code with
>Manx 3.4?  (or 3.6 as I will be upgrading to that soon).
>
>   For example, I know that static (global) variables are out, but are there
>any other things? (like string constants?)
>
>   While we are on the subject, what about reentrant code in all the other
>languages for the Amiga.. like pascal, and assembly, and modula2, and
>Lattice C  :-)?
>
>   Thanks.

	Mainly, you have to stay away from most link-library routines (C.LIB).
As you said, globals, unless they are constants, are out.  For example,
SysBase and DOSBase are globals but never change, so they are ok.  STDIO 
(in C.LIB) is DEFINATELY out.  If you stick to run-time library calls and
keep in mind your code might be running simultaniously in different contexes,
you should be fine.

	AVOID RETURNING STRUCTURES.  Many compilers, Aztec included (I'm
pretty sure), use static memory to hold structural return values.  I don't
know of anybody who uses the [mis]feature, though.

	STATIC variables, unless used purposefully, are also out.

NOTE:  This means using the main() entry point is out, as it sets up stdio.
I am not sure about using _main() ... it might work.  If all else fails,
you can compile your code +B, and assuming there are no other references
to .begin, the code is entered at the first module.  In this case you must
remember that global variables will NOT be zero'd initially, and neither
the DOS or  EXEC libraries will be open.

	Did I miss anything?

				-Matt
Technical Details
Message-ID: <8807240603.AA02259@cory.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!ucbvax!CORY.BERKELEY.EDU!dillon

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!ucbvax!CORY.BERKELEY.EDU!dillon
From: dillon@CORY.BERKELEY.EDU (Matt Dillon)
Newsgroups: comp.sys.amiga.tech
Subject: Re: how to write reentrant C code?
Message-ID: <8807240603.AA02259@cory.Berkeley.EDU>
Date: 24 Jul 88 06:03:54 GMT
Sender: daemon@ucbvax.BERKELEY.EDU
Lines: 35