Olin Lathrop | 2 Jul 15:00

Re: [PIC] using BREAK in 'C'

Michael Rigby-Jones wrote:
> I think you are missing Bills point.  Can you take the code you have
> just written and be sure it will compile and work on any arbitrary
> Pascal compiler?  Would you really want to have to have a diffierent
> implementaion of this code for each target you want to use it on?

That would be a relevant question if we were chosing a compiler from today's
available choices.  I was only pointing out that C is a really bad language
and used some examples based on Pascal to show there are other ways.  I'm
not advocating Pascal either, but its concepts are useful as counter
examples to C, especially since I'm pretty familiar with a language based on
those concepts.

> When I last used Pascal (a long time ago admittedly), I could find no
> way of defining static variables within a function, so end up using
> globals which is very ugly.  Has this situation changed?

There are several ways to define static variable.  One is to put variables
at the module level outside any function:

module xxx;

var
  ii: integer32;  {static variable with module scope}

procedure aaa;
begin
  end;

procedure bbb;
begin
  end;

Subroutines AAA and BBB can both reference the static variable II.  This is
useful when a subsystem needs private state that several of its routines
need to access.

Another way is to define the variable in a specifically named section:

procedure aaa;
var (mysection)
  ii: integer32;  {static variable with subroutine scope}
begin
  end;

Of course the choice of section name may be dependent on linker conventions
and definitions in other non-code files, such as the MPLINK control file on
PIC targets.

********************************************************************
Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products
(978) 742-9014.  Gold level PIC consultants since 2000.
--

-- 
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist


Gmane