It is currently Thu Jul 18, 2019 8:37 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Compiler doesn't complain if pointer variable typed in struc
PostPosted: Wed Jun 05, 2019 7:46 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4568
Location: Spa, relaxing and thinking, and learning...
When pointer variable is defined inside a structure, compiler does not complain if the pointer is defined with no existing var-type.

Code:
EnableExplicit

Structure var
  *m.DRI
EndStructure

define r.i,v.var
r.i=v.var\m
debug r

_________________
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend


Top
 Profile  
Reply with quote  
 Post subject: Re: Compiler doesn't complain if pointer variable typed in s
PostPosted: Wed Jun 05, 2019 8:16 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 13, 2010 3:45 pm
Posts: 861
No bug. A pointer is a pointer and for the structure it does not matter whether the type for the pointer is present or not.

If the structure would urge the pointer type, many things would not be possible, because no circle references for pointer variables would be possible any more.

_________________
sorry for my bad english


Top
 Profile  
Reply with quote  
 Post subject: Re: Compiler doesn't complain if pointer variable typed in s
PostPosted: Wed Jun 05, 2019 8:23 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4568
Location: Spa, relaxing and thinking, and learning...
I know, but what about a warning "not .DRI structure found in the complete code" ?
This topic should be placed in the 'feature requests' section :)

_________________
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend


Top
 Profile  
Reply with quote  
 Post subject: Re: Compiler doesn't complain if pointer variable typed in s
PostPosted: Wed Jun 05, 2019 8:49 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 13, 2010 3:45 pm
Posts: 861
PB as a single-pass compiler does not know at time of structure declaration what follows. On the other hand, I don't know where is your problem. At latest if you want to use the fields of your structure type 'DRI', you get an error message that DRI isn't defined.

Better is to move in the 'Coding Questions' section. :D

_________________
sorry for my bad english


Top
 Profile  
Reply with quote  
 Post subject: Re: Compiler doesn't complain if pointer variable typed in s
PostPosted: Thu Jun 06, 2019 9:33 am 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4568
Location: Spa, relaxing and thinking, and learning...
Single pass compiling can detect the declaration or not declaration of any structure defined in the code.
I think nobody here must put their own problems with any issue, but the problem with any issue. I this case, I have not problem with this topic, but i see a strangeness with it.
We know we get an error when any field of undeclared structure (DRI) is used.

_________________
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend


Top
 Profile  
Reply with quote  
 Post subject: Re: Compiler doesn't complain if pointer variable typed in s
PostPosted: Thu Jun 06, 2019 10:03 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13595
Location: France
It's the intended behaviour to allow circular dependencies


Top
 Profile  
Reply with quote  
 Post subject: Re: Compiler doesn't complain if pointer variable typed in s
PostPosted: Thu Jun 06, 2019 11:51 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 19, 2010 3:42 am
Posts: 529
Circular behaviour should have been done with declareStructure

No type check can stay because PureBasic is simply not a typed language:
Quote:
procedure test(*S.MyStructure)
;...
endProcedure
define *T.AnotherStructure
test(*T) ; -> no compiler complain here
define T1.AnotherStructure
test(*T) ; -> no compiler complain here


As PureBasic is intended to be an easier C, the whole behaviour is correct.

Is it a really big problem?


Top
 Profile  
Reply with quote  
 Post subject: Re: Compiler doesn't complain if pointer variable typed in s
PostPosted: Thu Jun 13, 2019 2:49 pm 
Offline
Addict
Addict

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 1046
Location: Russia
Fred wrote:
It's the intended behaviour to allow circular dependencies
Then why in this code compiler reports an error?
Code:
Declare Proc(*x.MyStruct)

Structure MyStruct
  x.l
  y.i
EndStructure

s.MyStruct
Proc(@s)

Procedure Proc(*x.MyStruct)
  If *x
    *x\x = 2
    *x\y = 4
  EndIf
EndProcedure

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
Reply with quote  
 Post subject: Re: Compiler doesn't complain if pointer variable typed in s
PostPosted: Thu Jun 13, 2019 3:15 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Sep 22, 2009 10:41 pm
Posts: 415
@UserRussian

Why
Code:
Proc(@s)
?
s is already declared as a hidden pointor. Add @ prefix tells us the procedure won't treat x or y, but an other structure managing internal pointor. This last one not defined here.

Code:
Proc(s)
seems to be the normal way.


Top
 Profile  
Reply with quote  
 Post subject: Re: Compiler doesn't complain if pointer variable typed in s
PostPosted: Thu Jun 13, 2019 5:08 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 2967
Location: Boston, MA
I am not a fan of wasted lines and Declares.
I have ~100k lines of code with maybe 3 Declares.(Prototypes are not Declares.)
This issue is solved by proper ordering for a single pass compiler. :wink:
Code:
;Declare Proc(*x.MyStruct)
Structure MyStruct
  x.l
  y.i
EndStructure
Procedure Proc(*x.MyStruct)
  If *x
    *x\x = 2
    *x\y = 4
  EndIf
EndProcedure
s.MyStruct
Proc(@s)

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Compiler doesn't complain if pointer variable typed in s
PostPosted: Thu Jun 13, 2019 5:53 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Sep 22, 2009 10:41 pm
Posts: 415
@Skywalk

Hello. Same remark as this one done previously.

Code:
Structure aStruc
   a.I
   b.I
EndStructure

Define.aStruc X

Debug X
Debug @X

Results are equal...

But it is sure structures must be written before declarings using these last one.

We are now talking about details where everybody is right.

To go back to the subject, inserting a pointor in a structure :
Code:
Structure var
   *a
EndStructure
This shows we stay free to choose whatever the pointor is pointing.

The pointor stays undefined and allows StructureUnion equivalents.


Top
 Profile  
Reply with quote  
 Post subject: Re: Compiler doesn't complain if pointer variable typed in s
PostPosted: Thu Jun 13, 2019 11:27 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 13, 2010 3:45 pm
Posts: 861
Olliv wrote:
@UserRussian

Why
Code:
Proc(@s)
?
s is already declared as a hidden pointor. Add @ prefix tells us the procedure won't treat x or y, but an other structure managing internal pointor. This last one not defined here.

Code:
Proc(s)
seems to be the normal way.
And what does this have to do with the contribution of User_Russian?


skywalk wrote:
I am not a fan of wasted lines and Declares.
I have ~100k lines of code with maybe 3 Declares.(Prototypes are not Declares.)
This issue is solved by proper ordering for a single pass compiler. :wink:
Although this is not directly related to User_Russian's contribution, it should be up to each user to decide how to arrange his procedures. Personally I prefer to arrange my procedures as they belong together and that is not possible without 'Declare'.



I must fully agree with User_Russian:

Pb should just skip this idiotic error message for pointers in declare parameters and everything is fine. Fread doesn't need to do anything other than simply ignore the type of pointers in this case.


@User_Russian
It is better to eliminate all not necessary code in the examples. Then there will be no unnecessary discussions.

_________________
sorry for my bad english


Top
 Profile  
Reply with quote  
 Post subject: Re: Compiler doesn't complain if pointer variable typed in s
PostPosted: Fri Jun 14, 2019 1:32 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3559
Location: Utah, USA
@User_Russian:
User_Russian wrote:
Then why in this code compiler reports an error?

The error can easily be removed with only a slight modification:
Code:
;Declare Proc(*x.MyStruct)
Declare Proc(*x) ;The structure of a pointer is not required for a parameter of a Declare procedure.

Structure MyStruct
  x.l
  y.i
EndStructure

s.MyStruct
Proc(@s)

Procedure Proc(*x.MyStruct)
  If *x
    *x\x = 2
    *x\y = 4
  EndIf
EndProcedure

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Compiler doesn't complain if pointer variable typed in s
PostPosted: Fri Jun 14, 2019 4:32 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3598
Location: Berlin, Germany
User_Russian wrote:
Fred wrote:
It's the intended behaviour to allow circular dependencies
Then why in this code compiler reports an error?

Fred was not talking about Declare().

To avoid problems like in your example code above, just write all structure definitions before any Declare() statements.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Compiler doesn't complain if pointer variable typed in s
PostPosted: Fri Jun 14, 2019 4:46 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Sep 22, 2009 10:41 pm
Posts: 415
Josh wrote:
And what does this have to do with the contribution of User_Russian?
You forget skywalk contribution : I do not know this technic about @StructuredVariable, not to say @StaticPointor.Integer .


For Declare:
Code:
Structure void
EndStructure

Declare proc1(*a.void)
Declare proc2(*a)

Procedure proc1(*a.integer)
EndProcedure

Structure Something
   FirstOne.I
EndStructure

Procedure proc2(*a.Something)
EndProcedure


Above, I cannot see error occuring.
Plus, I can read << *a.integer >> in the tool bar when cursor is on << *a.void >>.
Even just *a does not cause an error.

Also...

Code:
Structure aStruc
   *a.DontCare ; size of integer
   b.OtherStruc ; size of OtherStruc
EndStructure


Above we have a structure. We are fed up to manage Dontcare field address : we remove '*' character.
At the opposite : we want to manage OtherStruc which is a big structure during aStruc is often used to allocate lots of descriptors and so waste less memory : we insert '*' character. We prefer not to remove structure name to allow us to remember the thematic root of this field i.e. .

In a 'declare' line, this swap is unabled. But it is right that copy the bold following extract...

Procedure.D Op(A.D, B.D, *C.Status)

... to paste it below...

Decla <----- here

....is easy and quick. However, remove 'Status' can be useful to place declaration without worrying about structures place.

An other interest to keep a structure name near a structure field : knowing the initial configuration (circular or not).

And when we are a nut like me who uses first character of everything I find, MS for MainScreen, SoAs for Size Of AreaS, PsF for PreferenceS File, etc... Choose :

this:
Code:
Structure IamFine
   *MS.MainScreen
   *SoAs.SizeOfAreas
   *PsF.PreferencesFile
EndStructure


or that:
Code:
Structure IamTired
   *MS
   *SoAs
   *PsF
EndStructure


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye