[comp.sys.amiga.programmer] Any restrictions with making programs PURE?

231b3678@fergvax.unl.edu (Phil Dietz) (04/13/91)

Are there any restrictions with making 'C' programs PURE?  Is it just a matter
of linking it with cres.o?
 
  1)  Can you use global variables with resident programs?
 
  2)  Can you use global static structures?
 
Now this isnt for a Load-and-Stay resident program with cback.o, it's simple
a cres.o example.
 

---- Quote #2
                                                         Phil Dietz
    "You may be my friend,                 231b3678@fergvax.unl.edu
          but you're still a geek"           University of Nebraska

crazyrat@disk.uucp (@jap) (04/20/91)

In article <1991Apr12.203658.11790@unlinfo.unl.edu>, 231b3678@fergvax.unl.edu (Phil Dietz) writes:
> Are there any restrictions with making 'C' programs PURE?  Is it just a matter
> of linking it with cres.o?

From my experience, the only way a program can be pure is to make the code
re-entrant.  That is, all variable space has been DYNAMICALLY allocated.

I don't normally do re-entrant routines in C, but in Assembler.  It's much
easier..

> Now this isnt for a Load-and-Stay resident program with cback.o, it's simple
> a cres.o example.

@jap


-- 
Joel C. Justen      Crazyrat Productions Ltd.
CRAZYRAT@DISK.UUCP  JCJUST01@ulkyvx.BITNET 

mwm@pa.dec.com (Mike (My Watch Has Windows) Meyer) (04/23/91)

In article <1991Apr19.231119.6428@disk.uucp> crazyrat@disk.uucp (@jap) writes:
   In article <1991Apr12.203658.11790@unlinfo.unl.edu>, 231b3678@fergvax.unl.edu (Phil Dietz) writes:
   > Are there any restrictions with making 'C' programs PURE?  Is it just a matter
   > of linking it with cres.o?

   From my experience, the only way a program can be pure is to make the code
   re-entrant.  That is, all variable space has been DYNAMICALLY allocated.

This is correct.

   I don't normally do re-entrant routines in C, but in Assembler.  It's much
   easier..

This isn't. Linking with cres.o is enough to get the C compiler to
dynamically allocate your statics. That takes care of that. If you
need to refer to an absolute object (Custom comes to mind) you'll have
to declare it far. I vaguelly recall some compilation modes that don't
work with cres.o (-b0?), but don't have the details in handy.

	<mike


--
The sun is shining slowly.				Mike Meyer
The birds are flying so low.				mwm@pa.dec.com
Honey, you're my one and only.				decwrl!mwm
So pay me what you owe me.

dillon@overload.Berkeley.CA.US (Matthew Dillon) (04/25/91)

In article <MWM.91Apr23124114@raven.pa.dec.com> mwm@pa.dec.com (Mike (My Watch Has Windows) Meyer) writes:
>In article <1991Apr19.231119.6428@disk.uucp> crazyrat@disk.uucp (@jap) writes:
>   In article <1991Apr12.203658.11790@unlinfo.unl.edu>, 231b3678@fergvax.unl.edu (Phil Dietz) writes:
>   > Are there any restrictions with making 'C' programs PURE?  Is it just a matter
>   > of linking it with cres.o?
>...
>   I don't normally do re-entrant routines in C, but in Assembler.  It's much
>   easier..
>
>This isn't. Linking with cres.o is enough to get the C compiler to
>dynamically allocate your statics. That takes care of that. If you
>need to refer to an absolute object (Custom comes to mind) you'll have
>to declare it far. I vaguelly recall some compilation modes that don't
>work with cres.o (-b0?), but don't have the details in handy.
>
>	<mike

    Well, not quite.. with SAS/C you also have to #include <proto/all.h>,
    but it still isn't much.  With DICE you don't have to do a blasted
    thing except give the compiler the -r option.  <poof>, residentable
    reentrantable executable.

					-Matt

--

    Matthew Dillon	    dillon@Overload.Berkeley.CA.US
    891 Regal Rd.	    uunet.uu.net!overload!dillon
    Berkeley, Ca. 94708
    USA

mwm@pa.dec.com (Mike (My Watch Has Windows) Meyer) (04/25/91)

In article <dillon.6937@overload.Berkeley.CA.US> dillon@overload.Berkeley.CA.US (Matthew Dillon) writes:
       Well, not quite.. with SAS/C you also have to #include <proto/all.h>,
       but it still isn't much.

That's odd - I never use that file. On the other hand, I also
habitually use prototypes and pragmas for everything, and that could
well be the "required modes" I was mumbling about.

	<mike

--
[Our regularly scheduled .signature preempted.]		Mike Meyer
The Amiga 1000: Let's build _the_ hackers machine.	mwm@pa.dec.com
The Amiga 500: Let's build one as cheaply as possible!	decwrl!mwm
The Amiga 2000: Let's build one inside an IBM PC!

dillon@overload.Berkeley.CA.US (Matthew Dillon) (04/27/91)

In article <MWM.91Apr25101433@raven.pa.dec.com> mwm@pa.dec.com (Mike (My Watch Has Windows) Meyer) writes:
>In article <dillon.6937@overload.Berkeley.CA.US> dillon@overload.Berkeley.CA.US (Matthew Dillon) writes:
>	Well, not quite.. with SAS/C you also have to #include <proto/all.h>,
>	but it still isn't much.
>
>That's odd - I never use that file. On the other hand, I also
>habitually use prototypes and pragmas for everything, and that could
>well be the "required modes" I was mumbling about.
>
>	<mike

    What I meant was, if you want to make an Amiga OS call such as
    FindTask() you need the #pragma to be able to make such code
    residentable, thus have to #include the appropriate proto/?.h file.
    Otherwise SAS/C takes the tag from the large-data amiga.lib.

    With DICE you are only required to have prototypes if you use the -mRR
    (registered args) option, NOT if you simply want to make something
    residentable.

    It's not a big issue, but I *have* been forced more than once to
    include a massive amount of include files in SAS/C just to get
    something residentable, which often brings in extern's for library
    base variables which I definitely do NOT want.

				    -Matt

--

    Matthew Dillon	    dillon@Overload.Berkeley.CA.US
    891 Regal Rd.	    uunet.uu.net!overload!dillon
    Berkeley, Ca. 94708
    USA

GKZ117@uriacc.uri.edu (F. Michael Theilig) (04/28/91)

On 24 Apr 91 20:55:21 GMT Matthew Dillon said:
> [Stuff deleted]
>
>    Well, not quite.. with SAS/C you also have to #include <proto/all.h>,
>    but it still isn't much.  With DICE you don't have to do a blasted
>    thing except give the compiler the -r option.  <poof>, residentable
>    reentrantable executable.
>
>					-Matt
>
     I'd like to point out that this will not make it residentable with
 ARP's ARes.  It gets a checksum error.  Does anyone know how to make ARes
 like it?

--------
     F. Michael Theilig  -  The University of Rhode Island at Little Rest
                            GKZ117 at URIACC
                            RPG117 at URIACC

                                               Though you'd like to know.

jap@convex.cl.msu.edu (Joe Porkka) (04/29/91)

dillon@overload.Berkeley.CA.US (Matthew Dillon) writes:

>In article <MWM.91Apr25101433@raven.pa.dec.com> mwm@pa.dec.com (Mike (My Watch Has Windows) Meyer) writes:
>>In article <dillon.6937@overload.Berkeley.CA.US> dillon@overload.Berkeley.CA.US (Matthew Dillon) writes:
>>	Well, not quite.. with SAS/C you also have to #include <proto/all.h>,
>>	but it still isn't much.
>>

>    Otherwise SAS/C takes the tag from the large-data amiga.lib.
Try using the supplied "lib:small.lib", it does not have the C tags,
so you are forced to use the #pragmas. Doing this, the linker will
inform you when you forgot to include to proper pragmas.
(Besides, small.lib is smaller, so linking is faster)

>    With DICE you are only required to have prototypes if you use the -mRR
>    (registered args) option, NOT if you simply want to make something
>    residentable.

>    It's not a big issue, but I *have* been forced more than once to
>    include a massive amount of include files in SAS/C just to get
>    something residentable, which often brings in extern's for library
>    base variables which I definitely do NOT want.

If you #include <pragmas/something.h>, then you only get the pragma,
and not all the other junk.

dillon@overload.Berkeley.CA.US (Matthew Dillon) (05/01/91)

In article <1991Apr29.130835.2126@msuinfo.cl.msu.edu> jap@convex.cl.msu.edu (Joe Porkka) writes:
>dillon@overload.Berkeley.CA.US (Matthew Dillon) writes:
>
>>    something residentable, which often brings in extern's for library
>>    base variables which I definitely do NOT want.
>
>If you #include <pragmas/something.h>, then you only get the pragma,
>and not all the other junk.

    Yes, but then your source will only compile under SAS/C.  You have
    to use #ifdef to make it portable, cluttering the source.

				    -Matt

--

    Matthew Dillon	    dillon@Overload.Berkeley.CA.US
    891 Regal Rd.	    uunet.uu.net!overload!dillon
    Berkeley, Ca. 94708
    USA