To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 3470
3469  |  3471
Subject: 
Re: Linked Lists in BrickOS
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Thu, 9 Oct 2003 16:29:02 GMT
Viewed: 
2989 times
  
In lugnet.robotics.rcx.legos, Michael Purvis wrote:

pNext = (Node *)NULL;

It looks like this was the problem line. I didn't know the syntax for a pointer
to nothing. (in pascal it's just a constant...)

If you install cygwin and the cross compilers using my pre-packaged installer
(http://bricxcc.sourceforge.net/BricxCCSetupCygwin.exe) and my pre-packaged and
pre-built brickOS/leJOS installer
(http://bricxcc.sourceforge.net/BricxCCbrickOSleJOS.exe) then you should be able
to write your brickOS programs using GNU Pascal.  (see below)

btw-- how did you post code with indentations and have it not remove them? I'm
used to phpBB and the [code] tags, but we don't have those here...

I used spaces for my indentations - which BricxCC uses rather than tabs if you
have the Quick Tabs option checked.  That appears to be the only difference
between my post and yours.  If I looked at the raw form of your post I could see
the tabs just fine.

John Hansen
http://members.aol.com/johnbinder/bricxcc.htm

-- cut here for sample GNU pascal brickOS program --
program ptest;

uses
  conio, unistd, dsound;

type
  PNode = ^TNode;
  TNode = object
  private
    val : string[5];
    pNext : PNode;
  public
    constructor Create(const s : string);
    destructor Destroy;
    function Next : PNode;
    procedure SetNext(p : PNode);
    function Value : string;
  end;

  TList = object
  private
    p_head : PNode;
  public
    constructor Create;
    destructor Destroy;
    function Top : PNode;
    procedure Clear;
    procedure Push(const s : string);
    procedure Print;
  end;

{ TNode }

constructor TNode.Create(const s : string);
begin
  val := s;
  pNext := nil;
end;

destructor TNode.Destroy;
begin
  // nothing to destroy
end;

function TNode.Next : PNode;
begin
  Result := pNext;
end;

procedure TNode.SetNext(p : PNode);
begin
  pNext := p;
end;

function TNode.Value : string;
begin
  Result := val;
end;

{ TList }

constructor TList.Create;
begin
  p_head := nil;
end;

destructor TList.Destroy;
begin
  Clear;
end;

function TList.Top : PNode;
begin
  Result := p_head;
end;

procedure TList.Push(const s : string);
var
  n, tmp : PNode;
begin
  n := New(PNode, Create(s));
  tmp := p_head;
  p_head := n;
  p_head^.SetNext(tmp);
end;

procedure TList.Clear;
var
  p, tmp : PNode;
begin
  // delete all the nodes in our list
  p := Top;
  while p <> nil do
  begin
    tmp := p;
    p := p^.Next;
    Dispose(tmp, Destroy);
  end;
  p_head := nil;
end;

procedure TList.Print;
var
  p, tmp : PNode;
begin
  p := Top;
  while p <> nil do
  begin
    cputs(p^.Value);
    msleep(500);
    p := p^.Next;
  end;
end;

var
  List : TList;

begin
  List.Create;
  // do some stuff
  List.Push('Fun');
  List.Push('What');
  List.Push('ddddd');
  List.Push('ccccc');
  List.Push('bbbbb');
  List.Push('aaaaa');
  List.Print;
  List.Destroy;
end.



Message has 1 Reply:
  Re: Linked Lists in BrickOS
 
(...) Actually, it turned out that there was some leftover obj or mak files that were messing up the compiler. I purged the directory, and all was well. Thanks for the tip on tabbing. Just wanted to confirm that a BrickOS pointer is only 2 bytes... (...) (21 years ago, 10-Oct-03, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  Re: Linked Lists in BrickOS
 
(...) Yeah, this was the problem. It hadn't occurred to me that BricxCC wasn't saving the file before making. Whoops. (...) Yes, tremendously (...) It looks like this was the problem line. I didn't know the syntax for a pointer to nothing. (in (...) (21 years ago, 9-Oct-03, to lugnet.robotics.rcx.legos)

8 Messages in This Thread:




Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR