Page 1 of 1

PB5.00: nonexisting struc in struc = no error

Posted: Mon Nov 05, 2012 10:48 pm
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

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

Posted: Mon Nov 05, 2012 11:27 pm
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).

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

Posted: Tue Nov 06, 2012 12:08 am
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

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

Posted: Tue Nov 06, 2012 12:20 am
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.

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

Posted: Tue Nov 06, 2012 12:34 am
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?

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

Posted: Tue Nov 06, 2012 12:38 am
by Fred
The end check is possible and will be added.

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

Posted: Tue Nov 06, 2012 12:51 am
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.

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

Posted: Tue Nov 06, 2012 1:13 am
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).

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

Posted: Tue Nov 06, 2012 10:30 am
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

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

Posted: Wed Jan 09, 2013 2:23 pm
by Fred
Actually I changed my mind, as it's not an issue, you will notice it when accessing the field.

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

Posted: Thu Jan 17, 2013 2:23 pm
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 ??