Page 1 of 1

Struct explanation request

Posted: Sun Jan 14, 2024 2:41 pm
by Inner

Code: Select all

struct zz_vfs_dri_s {
  const char * name;			  /**< friendly name.      */
  zz_err_t (*reg)(zz_vfs_dri_t);	  /**< register driver.    */
  zz_err_t (*unreg)(zz_vfs_dri_t);	  /**< un-register driver. */
  zz_u16_t (*ismine)(const char *);	  /**< is mine.            */
  zz_vfs_t (*new)(const char *, va_list); /**< create VFS.         */
  void	   (*del)(zz_vfs_t);		  /**< destroy VFS.        */
  const
  char *   (*uri)(zz_vfs_t);			/**< get URI.       */
  zz_err_t (*open)(zz_vfs_t);			/**< open.          */
  zz_err_t (*close)(zz_vfs_t);			/**< close.         */
  zz_u32_t (*read)(zz_vfs_t, void *, zz_u32_t); /**< read.          */
  zz_u32_t (*tell)(zz_vfs_t);			/**< get position.  */
  zz_u32_t (*size)(zz_vfs_t);			/**< get size.      */
  zz_err_t (*seek)(zz_vfs_t,zz_u32_t,zz_u8_t);	/**< offset,whence. */
};
name is simple, what I've never encountered before is the lines that state things enclosed in brackets; eg.

zz_err_t (*seek)(zz_vfs_t,zz_u32_t,zz_u8_t);

zz_err_t is obviously a typedef :evil:
*seek is the name of the variable within the structure. no issue there.

(zz_vfs_t,zz_u32_t,zz_u8_t) .. what the? never see this behavior before, which is odd I thought I knew structs.

Re: Struct explanation request

Posted: Sun Jan 14, 2024 4:24 pm
by juergenkulow

Re: Struct explanation request

Posted: Sun Jan 14, 2024 6:47 pm
by Inner
I'm guessing I can just ignore the casting then and just translate it to the appropriate type, as what I am reading from your links really doesn't make things much clearer, 'probably' because I'd never do something so asinine in the first place and thus due to a lack of understanding on my part I don't see how it's useful for a c programmer at least, so for PureBasic I'd assume those variables would become *seek.l etc.. and the rest is deposited in the trash where it belongs.

Re: Struct explanation request

Posted: Sun Jan 14, 2024 9:42 pm
by infratec
something like this:

Code: Select all

Prototype.i Prototype_reg(zz_vfs_dri_t.i)
Prototype.i Prototype_unreg(zz_vfs_dri_t.i)
Prototype.u Prototype_ismine(*char)
Prototype.i Prototype_new(*char, *va_list)
Prototype Prototype_del(zz_vfs_t.i)
Prototype.i Prototype_uri(zz_vfs_t.i)
Prototype.i Prototype_open(zz_vfs_t.i)
Prototype.i Prototype_close(zz_vfs_t.i)
Prototype.l Prototype_read(zz_vfs_t.i, *buffer, size.l)
Prototype.l Prototype_tell(zz_vfs_t.i)
Prototype.l Prototype_size(zz_vfs_t.i)
Prototype.i Prototype_seek(zz_vfs_t.i, p1.l, p2.a)

Structure zz_vfs_dri_s
  *name;			  /**< friendly name.      */
  reg.Prototype_reg
  unreg.Prototype_unreg
  ismine.Prototype_ismine
  uri.Prototype_uri
  open.Prototype_open
  close.Prototype_close
  Read.Prototype_read
  tell.Prototype_tell
  size.Prototype_size
  seek.Prototype_seek
EndStructure
This are addresses of functions.

Maybe .i is .l
Maybe Prototype is PrototypeC

If you have to write tis procedures, maybe you need ProcedureC

Re: Struct explanation request

Posted: Sun Jan 14, 2024 10:24 pm
by Inner
infratec wrote: Sun Jan 14, 2024 9:42 pm something like this:

Code: Select all

Prototype.i Prototype_reg(zz_vfs_dri_t.i)
Prototype.i Prototype_unreg(zz_vfs_dri_t.i)
Prototype.u Prototype_ismine(*char)
Prototype.i Prototype_new(*char, *va_list)
Prototype Prototype_del(zz_vfs_t.i)
Prototype.i Prototype_uri(zz_vfs_t.i)
Prototype.i Prototype_open(zz_vfs_t.i)
Prototype.i Prototype_close(zz_vfs_t.i)
Prototype.l Prototype_read(zz_vfs_t.i, *buffer, size.l)
Prototype.l Prototype_tell(zz_vfs_t.i)
Prototype.l Prototype_size(zz_vfs_t.i)
Prototype.i Prototype_seek(zz_vfs_t.i, p1.l, p2.a)

Structure zz_vfs_dri_s
  *name;			  /**< friendly name.      */
  reg.Prototype_reg
  unreg.Prototype_unreg
  ismine.Prototype_ismine
  uri.Prototype_uri
  open.Prototype_open
  close.Prototype_close
  Read.Prototype_read
  tell.Prototype_tell
  size.Prototype_size
  seek.Prototype_seek
EndStructure
This are addresses of functions.

Maybe .i is .l
Maybe Prototype is PrototypeC

If you have to write tis procedures, maybe you need ProcedureC
now it is sort of making some sense, I'm guess the address of those prototypes needs to be passed back to the variables within the structure for the lib/dll to be able to call those functions (pardon me) procedures properly.

:x that's gonna give my Header Assistant a margarine, not only do we need to build the Structure properly but also build stub type func.. sorry Procedures that are empty, welp that's why it an assistant not a total converter. :shock: :|

https://github.com/melony-cmd/PB-CTypeTable -- just in case you was wondering.

Re: Struct explanation request

Posted: Mon Jan 15, 2024 8:06 am
by Denis
Very interesting discussion for me as I'm really a beginner coder in C.

Re: Struct explanation request

Posted: Mon Jan 15, 2024 9:12 am
by Inner
Denis wrote: Mon Jan 15, 2024 8:06 am Very interesting discussion for me as I'm really a beginner coder in C.
As useful as the language is/was has been it's a pig of language, ridiculously overtyped and casted wrapped up in a ball of utterly useless functionality that only aids the 'nerd' get his thing on to bamboozle the rest of the 'sane' programmers out there, it's 2024 Windows 12 should have been written in basic by now, maybe even ... PureBasic :D

Re: Struct explanation request

Posted: Mon Jan 15, 2024 11:51 am
by Denis
Inner wrote: Mon Jan 15, 2024 9:12 am
Denis wrote: Mon Jan 15, 2024 8:06 am Very interesting discussion for me as I'm really a beginner coder in C.
As useful as the language is/was has been it's a pig of language, ridiculously overtyped and casted wrapped up in a ball of utterly useless functionality that only aids the 'nerd' get his thing on to bamboozle the rest of the 'sane' programmers out there, it's 2024 Windows 12 should have been written in basic by now, maybe even ... PureBasic :D
:mrgreen:

Re: Struct explanation request

Posted: Thu Feb 01, 2024 5:20 pm
by Inner
Denis wrote: Mon Jan 15, 2024 11:51 am
Inner wrote: Mon Jan 15, 2024 9:12 am
Denis wrote: Mon Jan 15, 2024 8:06 am Very interesting discussion for me as I'm really a beginner coder in C.
As useful as the language is/was has been it's a pig of language, ridiculously overtyped and casted wrapped up in a ball of utterly useless functionality that only aids the 'nerd' get his thing on to bamboozle the rest of the 'sane' programmers out there, it's 2024 Windows 12 should have been written in basic by now, maybe even ... PureBasic :D
:mrgreen:
Did you think I was jesting..
In the early days I understood why we used binary (better languages hadn't been invented yet)
In the early days I understood why we used asm (better languages hadn't been invented yet)
In the early days I understood why we used cobal/c/pascal (better languages hadn't been invented yet)
(Basic had been invented somewhere along this time line, but I understood why it wasn't used mainstream)

Today, I will never understand why we degenerated into C/C++/C#/C yo moma version you get the point, in stead of making things easier we've made it harder, it's not like the pragmatical problems cannot be solved with basic the question is why hasn't it, the only conclusion I can come to is ego, and gate keeping if everyone and their pet dog/cat or python could do it, programmers just become another toilet paper roll, well I want to be a toilet paper roll. :D :mrgreen:

Re: Struct explanation request

Posted: Thu Feb 01, 2024 6:34 pm
by skywalk
System languages needed pointers to be efficient.
Even Fortran added pointers later.
Basic had clunky varptr() and addressof().

Yes, C++ became a bloated mess with technical debt and over a 1000 pages of definitions.
But, you can still choose to code C++ with a C approach and do very well.

Re: Struct explanation request

Posted: Fri Feb 02, 2024 3:15 pm
by Inner
skywalk wrote: Thu Feb 01, 2024 6:34 pm System languages needed pointers to be efficient.
Even Fortran added pointers later.
Basic had clunky varptr() and addressof().

Yes, C++ became a bloated mess with technical debt and over a 1000 pages of definitions.
But, you can still choose to code C++ with a C approach and do very well.
All true, I realize the reality of cause it is the way it is, but I always thought things where supposed to get simpler not more complicated when I first started programming 35+ years ago.