nested struct conversion

General FreeBASIC programming questions.
Post Reply
stan1958
Posts: 5
Joined: Oct 24, 2020 21:17

nested struct conversion

Post by stan1958 »

Struggling to convert a nested struct C

Code: Select all

'C code

struct VFBE_canvas{
    struct elements{
        int a;
        int b;
    } internalData;
    int c;
}
Converted FB Code

Code: Select all

type elements
  a as long
  b as long
end type

type VFBE_canvas
  internalData as elements
  int c
end type
The above conversion looks easy, However I am struggling to convert the below struct

Code: Select all

struct vfbe_canvas {
    int ref;
    int contours;
    vfbe_canvas_t start;
    struct {
        vfbe_canvas_element_t* data;
        int size;
        int capacity;
    } elements;
    struct {
        vfbe_canvas_t* data;
        int size;
        int capacity;
    } points;
};
BR

Stan
paul doe
Moderator
Posts: 1796
Joined: Jul 25, 2017 17:22
Location: Argentina
Contact:

Re: nested struct conversion

Post by paul doe »

Code: Select all

type vfbe_canvas
  as long ref
  as long contours
  as vfbe_canvas_t start
  
  type elements_t
    as vfbe_canvas_element_t ptr data
    as long size
    as long capacity
  end type
  
  as elements_t elements
  
  type points_t
    as vfbe_canvas_t ptr data
    as long size
    as long capacity
  end type
  
  as points_t points
end type
Imortis
Moderator
Posts: 1947
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: nested struct conversion

Post by Imortis »

EDIT: I see paul doe has given a better answer. Also, I missed the fact that nested types can now be done in FB, starting at 1.10.0. Learn something new everyday.
stan1958
Posts: 5
Joined: Oct 24, 2020 21:17

Re: nested struct conversion

Post by stan1958 »

Thank You

paul doe & imortis.

That was so fast.

Yes in the document indeed it is mentioned about nested types, I am a sloow learner.
paul doe
Moderator
Posts: 1796
Joined: Jul 25, 2017 17:22
Location: Argentina
Contact:

Re: nested struct conversion

Post by paul doe »

No prob. Btw, I've corrected my answer (see above). Otherwise it won't work as intended in FB.
dodicat
Posts: 8140
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: nested struct conversion

Post by dodicat »

What is wrong here I wonder, 1.10.1 windows??
Paul doe's code snippet.

C:\Users\wlhut\Desktop\fb\fb10.1\FreeBASIC-1.10.1-winlibs-gcc-9.3.0\FreeBASIC-1.10.1-winlibs-gcc-9.3.0\fbc64.exe


...QuickTEMP.bas(4) error 14: Expected identifier, found 'vfbe_canvas_t' in 'as vfbe_canvas_t start'
...QuickTEMP.bas(7) error 14: Expected identifier, found 'vfbe_canvas_element_t' in 'as vfbe_canvas_element_t ptr data'
...QuickTEMP.bas(15) error 14: Expected identifier, found 'vfbe_canvas_t' in 'as vfbe_canvas_t ptr data'

Fail!
Jattenalle
Posts: 51
Joined: Nov 17, 2023 14:41
Contact:

Re: nested struct conversion

Post by Jattenalle »

dodicat wrote: Sep 04, 2024 21:32 What is wrong here I wonder, 1.10.1 windows??
Paul doe's code snippet.

C:\Users\wlhut\Desktop\fb\fb10.1\FreeBASIC-1.10.1-winlibs-gcc-9.3.0\FreeBASIC-1.10.1-winlibs-gcc-9.3.0\fbc64.exe


...QuickTEMP.bas(4) error 14: Expected identifier, found 'vfbe_canvas_t' in 'as vfbe_canvas_t start'
...QuickTEMP.bas(7) error 14: Expected identifier, found 'vfbe_canvas_element_t' in 'as vfbe_canvas_element_t ptr data'
...QuickTEMP.bas(15) error 14: Expected identifier, found 'vfbe_canvas_t' in 'as vfbe_canvas_t ptr data'

Fail!
OP only provided a struct snippet he needed help converting to FB, not a full compileable source.
Of course there will be missing pieces as OP didn't paste the entire source, nor was that ever implied.
dodicat
Posts: 8140
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: nested struct conversion

Post by dodicat »

removed
Last edited by dodicat on Sep 05, 2024 13:28, edited 1 time in total.
Jattenalle
Posts: 51
Joined: Nov 17, 2023 14:41
Contact:

Re: nested struct conversion

Post by Jattenalle »

dodicat wrote: Sep 05, 2024 10:13 I see.
So I have to make my own up.
[...]
Please don't derail genuine topics with inane spam. It helps noone.
dodicat
Posts: 8140
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: nested struct conversion

Post by dodicat »

I'll take it off.
Lost Zergling
Posts: 600
Joined: Dec 02, 2011 22:51
Location: France

Re: nested struct conversion

Post by Lost Zergling »

Maybe I'm wrong : renaming a sub struct so as to pass a nested ptr ref ?
Post Reply