Re: Dereferencing a pointer (accessing a structure member)

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
Hated Moron

Re: Dereferencing a pointer (accessing a structure member)

Post by Hated Moron »

On 13/08/2023 22:47, Alex Farlie via groups.io wrote (cross-posted from the Discussion Group):
How would something like a line:

Code: Select all

Graph^.GraphNode^.NodeWeight 
(which is Pascal/Modula2 style code) be written in BBC Basic for SDL?
I'm not familiar with the Pascal/Modula-2 syntax but I presume the code is equivalent to this in C:

Code: Select all

Graph->GraphNode->NodeWeight 
BBC BASIC doesn't have an exact equivalent to the C -> operator so you have to do it in multiple steps, something like this (where pGraph is a pointer to a Graph{} structure and pGraphNode a pointer to a GraphNode{} structure):

Code: Select all

PTR(Graph{}) = pGraph
PTR(GraphNode{}) = Graph.pGraphNode
PRINT GraphNode.NodeWeight
Since this is a BBC BASIC language question, it makes no difference whether it is BBC BASIC for Windows or BBC BASIC for SDL 2.0, they implement the same language syntax.
Hated Moron

Re: Dereferencing a pointer (accessing a structure member)

Post by Hated Moron »

Hated Moron wrote: Mon 14 Aug 2023, 08:46
On 13/08/2023 22:47, Alex Farlie via groups.io wrote (cross-posted from the Discussion Group):
How would something like [this] be written in BBC Basic for SDL?
BBC BASIC doesn't have an exact equivalent to the C -> operator so you have to do it in multiple steps...
Did this answer your question?
alex_farlie
Posts: 2
Joined: Tue 03 Apr 2018, 22:44

Re: Dereferencing a pointer (accessing a structure member)

Post by alex_farlie »

Hated Moron wrote: Sun 20 Aug 2023, 16:12
Hated Moron wrote: Mon 14 Aug 2023, 08:46
On 13/08/2023 22:47, Alex Farlie via groups.io wrote (cross-posted from the Discussion Group):
How would something like [this] be written in BBC Basic for SDL?
BBC BASIC doesn't have an exact equivalent to the C -> operator so you have to do it in multiple steps...
Did this answer your question?
(With apologies for a duplicate posting).
Yes . And you were correct about the C style synatx. I used the Modula2/Pascal version because it was what I was familar with :) .

I'd been keeping a low profile, and did not seem to have "notifications" enabled.