Structure reference

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Joubarbe
Enthusiast
Enthusiast
Posts: 555
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Structure reference

Post by Joubarbe »

Following this thread: viewtopic.php?f=13&t=76294
It would be good to nuance the "not a structure" compiler error:

Code: Select all

Structure _struc
  int.i
EndStructure

s = _struc ; *s = @_struc?
Debug _struc  ; 0.
Debug s       ; 0.
*buffer._struc = AllocateStructure(s) ; ERROR.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Structure reference

Post by Josh »

Code: Select all

s = _struc
What are you doing with this command or what do you think this command does?

Sorry, your code is complete nonsense, you should try to understand structures. In any case, you should use EnableExplicit, then you will find your bug somewhere else.
sorry for my bad english
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Structure reference

Post by Denis »

Joubarbe wrote:Following this thread: viewtopic.php?f=13&t=76294
It would be good to nuance the "not a structure" compiler error:

Code: Select all

Structure _struc
  int.i
EndStructure

s = _struc ; *s = @_struc?
Debug _struc  ; 0.
Debug s       ; 0.
*buffer._struc = AllocateStructure(s) ; ERROR.
Oh la la la Joubarbe...
The message is correct for me, _struc is the only declared structure in your "code"
What isn't correct is that you write this
s = _struc
Did try to have an equivalent name for _struc?

a variable is not a structure, a variable could be based on a structure.

If you really write code like this, you have to learn to understand what a structure is like Josh wrote.
A+
Denis
Joubarbe
Enthusiast
Enthusiast
Posts: 555
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Structure reference

Post by Joubarbe »

Of course this code is wrong, that’s not the point. But yeah forget it, if structure was a class, you would maybe understand the concept of referencing a class, like getClass() in Java. With the Macro system, and how lists work, it would be good to have that kind of thing to make your own list system and not caring about the structure type. I understand structures are a compiler thing, and that would probably require a ton of work to change how things are done under the hood, but something is missing here. If you don’t understand it, too bad (the point was also to read the thread I linked there).
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Structure reference

Post by mk-soft »

Structure descriptions are not available at runtime.
Only the description of the data to be processed that is required at runtime is available in an internal table (AllocateStructure, FreeStructure). Only offset and type of string, arrays, lists, maps are stored in this table. Not the other data types.

To pass the data type of a structure you have to define it in the structure.

The Windows-API also does this partly in its structures.

Code: Select all

Structure udtData1
  Size.i
  Type.i
  String.s
  ; ...
EndStructure

Structure udtData1
  Size.i
  Type.i
  iVal1.i
  iVal2.i
  ; ...
EndStructure
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Joubarbe
Enthusiast
Enthusiast
Posts: 555
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Structure reference

Post by Joubarbe »

Ok thanks mk-soft, always helpful. Your answer confirms that what I want is not really achievable at the moment. Will code a few more lines instead :)
Post Reply