PB5.00: nonexisting struc in struc = no error

Just starting out? Need help? Post your questions and find answers here.
User avatar
Regenduft
Enthusiast
Enthusiast
Posts: 121
Joined: Mon Mar 02, 2009 9:20 pm
Location: Germany

PB5.00: nonexisting struc in struc = no error

Post by Regenduft »

PureBasic 5.00 x64 (final) on Windows 7

The following code can be compiled without getting an error message or warning:

Code: Select all

EnableExplicit

Structure foo
  *foo.ThisStructureDoesNotExistButPureBasicDoesNotMind ; <- remove asterisk to get an error
EndStructure

Define foo.foo
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: PB5.00: nonexisting struc in struc = no error

Post by Shield »

I agree this should throw an error during compilation (consistency).
However, it doesn't have side effects, since pointers are always the same size
and it is also required for forward declarations (i.e. you can use structures for pointers before they are actually defined).
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: PB5.00: nonexisting struc in struc = no error

Post by Demivec »

It isn't a bug. It is by design.

Otherwise you couldn't do this:

Code: Select all

Structure foo
  *ptrBoo.boo  ;boo structure not yet defined at this point in code
EndStructure

Structure boo
  *ptrFoo.foo
EndStructure
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: PB5.00: nonexisting struc in struc = no error

Post by Shield »

Yeah, but the compiler could check at the end if the structure has actually been defined.
As I said, it doesn't have any side effects. If you have a typo you will notice that when you try to access the fields.

By the way, C++ compilers (at least the one I tested) don't do the check either, but I'd imagine it's because of late linking
of classes (which isn't really possible with PB). So I'd vote for adding a check.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: PB5.00: nonexisting struc in struc = no error

Post by Demivec »

Shield wrote:Yeah, but the compiler could check at the end if the structure has actually been defined.
Wouldn't that require the compiler making two passes instead of one?
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB5.00: nonexisting struc in struc = no error

Post by Fred »

The end check is possible and will be added.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: PB5.00: nonexisting struc in struc = no error

Post by Shield »

Demivec wrote:
Shield wrote:Yeah, but the compiler could check at the end if the structure has actually been defined.
Wouldn't that require the compiler making two passes instead of one?

No. While the compiler goes through it knows what structures have been defined and what structures have been used.
If a structure has been used which hasn't been defined an error should be thrown.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: PB5.00: nonexisting struc in struc = no error

Post by luis »

Shield wrote: No. While the compiler goes through it knows what structures have been defined and what structures have been used.
If a structure has been used which hasn't been defined an error should be thrown.
That's why should be very easy to add a report for ALL the variables defined but never used.
It would be useful to remove unwanted zombies (in time working on the same code it happens).
"Have you tried turning it off and on again ?"
A little PureBasic review
Ulix
User
User
Posts: 48
Joined: Wed Jan 23, 2008 12:45 pm
Location: France, Montpellier

Re: PB5.00: nonexisting struc in struc = no error

Post by Ulix »


That's why should be very easy to add a report for ALL the variables defined but never used.
It would be useful to remove unwanted zombies (in time working on the same code it happens).
+1
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB5.00: nonexisting struc in struc = no error

Post by Fred »

Actually I changed my mind, as it's not an issue, you will notice it when accessing the field.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: PB5.00: nonexisting struc in struc = no error

Post by Psychophanta »

I still thing there is a clever way to solve this inconvenience (inconsistence indeed) with the one-pass compiling scheme. (Even in the C++ seems also not solved)
For future ??
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply