New fbc branch ('inheritance') on sourceforge (fbc SVN)

For other topics related to the FreeBASIC project or its community.
sir_mud
Posts: 1401
Joined: Jul 29, 2006 3:00
Location: US
Contact:

Postby sir_mud » Apr 30, 2011 4:31

Includes latest stock lib dir and fbc.exe, just expand into your fbc directory (back your copy of fbc.exe and the lib dir up first)
http://jafile.com/uploads/sir_mud/fbc_v ... h_win32.7z
fxm
Posts: 9177
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Postby fxm » Apr 30, 2011 9:26

sir_mud wrote:Includes latest stock lib dir and fbc.exe, just expand into your fbc directory (back your copy of fbc.exe and the lib dir up first)
http://jafile.com/uploads/sir_mud/fbc_v ... h_win32.7z

Thank you very much sir_mud.
Everyone will now be able to start playing around with the inheritance!

It might be nice to have a list of keywords (with their meanings) specific to this extension:
Extends, Base, Object, Is, ...?
fxm
Posts: 9177
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Postby fxm » Apr 30, 2011 11:15

sir_mud wrote:Includes latest stock lib dir and fbc.exe, just expand into your fbc directory (back your copy of fbc.exe and the lib dir up first)
http://jafile.com/uploads/sir_mud/fbc_v ... h_win32.7z

I get systematically these 2 warnings at each compilation:
    Compiler output:
    Warning: .drectve `-aligncomm:"___fb_ctx",5' unrecognized
    Warning: .drectve `-aligncomm:"___fb_con",5' unrecognized
Is is normal?


Solved by dkl build:
fbc-oop-snapshot-win32.zip
available at this below post:
http://www.freebasic.net/forum/viewtopi ... 572#156572
Last edited by fxm on Apr 30, 2011 20:37, edited 1 time in total.
fxm
Posts: 9177
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Postby fxm » Apr 30, 2011 14:07

In this short example:

Code: Select all

Type UDT1
  name as string
End Type

Type UDT2 extends UDT1
  name as string
End Type

Type UDT3 extends UDT2
  name as string
  declare constructor()
  declare constructor(Byref Nom As String)
End Type

constructor UDT3 (Byref Nom As String)
  base.name = Nom
End constructor

Dim test as UDT3 = UDT3("Tom")
Print test.name
Print cast(UDT2, test).name
Print cast(UDT1, test).name

Why compilation error?
error 22: Internal!, ASTINCOFFSET in 'Print cast(UDT2, test).name',
when 'Print cast(UDT1, test).name' compile successfully.

Only UDT3/UDT2 member function can access to member data 'name' of UDT2?
Last edited by fxm on May 01, 2011 17:59, edited 4 times in total.
dkl
Site Admin
Posts: 3209
Joined: Jul 28, 2005 14:45
Location: Germany

Postby dkl » Apr 30, 2011 14:20

fxm wrote:I get systematically these 2 warnings at each compilation:
    Compiler output:
    Warning: .drectve `-aligncomm:"___fb_ctx",5' unrecognized
    Warning: .drectve `-aligncomm:"___fb_con",5' unrecognized
Is is normal?


I think that happens when the FB runtime is compiled with a current MinGW setup (GCC 4.5). The binutils 2.15 coming with FB are too old for that. I don't know whether it causes any problems though. I'm using a semi-recent MinGW/TDM-GCC setup that works (see http://www.freebasic.net/wiki/wikka.php?wakka=SVNWin32MSYS.

By the way, the reason for the old binutils in FB-win32 is that in all binutils versions since 2.18 the linker has a bug that affects FB. Maybe we could use binutils 2.17, but besides that the next binutils release (2.22) should have the bug fixed, and as long as there are no other problems (with debugging for example) then FB will work with that.
fxm
Posts: 9177
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Postby fxm » Apr 30, 2011 14:53

In this other very short example:

Code: Select all

Type UDT1
  Protected:
    name as string
End Type

Dim test As UDT1
test.name = "Hello"

Why compilation error?
error 175: Illegal member access, found 'name' in 'test.name = "Hello"'

The behavior of protected member access has changed?
'Protected:' seems now to act as 'Private:'!
fxm
Posts: 9177
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Postby fxm » Apr 30, 2011 15:41

sir_mud wrote:Includes latest stock lib dir and fbc.exe, just expand into your fbc directory (back your copy of fbc.exe and the lib dir up first)
http://jafile.com/uploads/sir_mud/fbc_v ... h_win32.7z


- When I try to compile with this new fbc a program which runs with the official fbc, I obtain the following failed compilation:
    Command executed:
    "d:\Documents and Settings\t0003830\Mes documents\FreeBASIC-win-SVN-20110428+inheritance\fbc.exe" "D:\Prg\FXM\Montagne\FBIDETEMP.bas"

    Compiler output:
    Warning: .drectve `-aligncomm:"_fb_win32",5' unrecognized
    Warning: .drectve `-aligncomm:"_fb_lzw_entry",5' unrecognized
    Warning: .drectve `-aligncomm:"___fb_gl",5' unrecognized
    Warning: .drectve `-aligncomm:"___fb_ctx",5' unrecognized
    Warning: .drectve `-aligncomm:"___fb_con",5' unrecognized
    d:\Documents and Settings\t0003830\Mes documents\FreeBASIC-win-SVN-20110428+inheritance\lib\win32/libfb.a(libfb_str_convfrom.o):libfb_str_convfrom.c:(.text+0x7e): undefined reference to `__strtod'

    Results:
    Compilation failed

    System:
    FBIde: 0.4.6
    fbc: FreeBASIC Compiler - Version 0.22.0 (04-29-2011) for win32 (target:win32)
    OS: Windows XP (build 2600, Service Pack 2)

- Other similar programs will still compile fine.


Solved by dkl build:
fbc-oop-snapshot-win32.zip
available at this below post:
http://www.freebasic.net/forum/viewtopi ... 572#156572
Last edited by fxm on Apr 30, 2011 20:36, edited 1 time in total.
Imortis
Moderator
Posts: 1629
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Postby Imortis » Apr 30, 2011 16:37

fxm wrote:In this other very short example:

Code: Select all

Type UDT1
  Protected:
    name as string
End Type

Dim test As UDT1
test.name = "Hello"

Why compilation error?
error 175: Illegal member access, found 'name' in 'test.name = "Hello"'

The behavior of protected member access has changed?
'Protected:' seems now to act as 'Private:'!


Protected only allows access from within a class or one of it's sub-classes.
You are trying to access the member from the main body of the program. That won't work. You have to access it from a member of the class.
fxm
Posts: 9177
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Postby fxm » Apr 30, 2011 16:49

Imortis wrote:Protected only allows access from within a class or one of it's sub-classes.
You are trying to access the member from the main body of the program. That won't work. You have to access it from a member of the class.

- Before, my previous example worked:
So that was before the keyword 'Protected:' does not work correctly.

- Yet it did not behave the same as 'Public:', because it prohibited access from a member of another class, but it did not prohibit access from the main body of the program.
agamemnus
Posts: 1842
Joined: Jun 02, 2005 4:48

Postby agamemnus » Apr 30, 2011 18:02

fxm wrote:So that was before the keyword 'Protected:' does not work correctly.


So it works correctly now, since it's not letting you do that.

BTW I am also against "protected" as a keyword, :) on two bases:

1) If you want a UDT to inherit a base UDT, how does it make sense that you don't want the bigger UDT to see all the functions of the base UDT? In what case would you want something like that? (no sense to have both protected or private)

2) Even if there was such an example, why two keywords to muddle the language? Why not just have a compound keyword, like "private inherits" (or "private extends"..) or something like that?
dkl
Site Admin
Posts: 3209
Joined: Jul 28, 2005 14:45
Location: Germany

Postby dkl » Apr 30, 2011 20:03

fxm
Posts: 9177
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Postby fxm » Apr 30, 2011 20:31


Yes, great.
All my problems of warning and failed compilation disappear with this win32 build!

- For my part, it remains only this previous question:
http://www.freebasic.net/forum/viewtopi ... 538#156538 + remark post below
- and this other:
It might be nice to have a list of keywords (with their meanings) specific to this extension: 'Extends', 'Base', 'Object', 'Is', ...?
Last edited by fxm on May 01, 2011 9:11, edited 2 times in total.
fxm
Posts: 9177
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Postby fxm » May 01, 2011 8:17

fxm wrote:In this short example:

Code: Select all

Type UDT1
  name as string
End Type

Type UDT2 extends UDT1
  name as string
End Type

Type UDT3 extends UDT2
  name as string
  declare constructor()
  declare constructor(Byref Nom As String)
End Type

constructor UDT3 (Byref Nom As String)
  base.name = Nom
End constructor

Dim test as UDT3 = UDT3("Tom")
Print test.name
Print cast(UDT2, test).name
Print cast(UDT1, test).name

Why compilation error?
error 22: Internal!, ASTINCOFFSET in 'Print cast(UDT2, test).name',
when 'Print cast(UDT1, test).name' compile successfully.

Only UDT3/UDT2 member function can access to member data 'name' of UDT2?

But the same example runs via pointer use!
Print cast(UDT2 ptr, @test)->name
or
Print *cast(UDT2 ptr, @test).name
Last edited by fxm on May 01, 2011 18:00, edited 1 time in total.
fxm
Posts: 9177
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Postby fxm » May 01, 2011 11:51

agamemnus wrote:
fxm wrote:So that was before the keyword 'Protected:' does not work correctly.


So it works correctly now, since it's not letting you do that.

BTW I am also against "protected" as a keyword, :) on two bases:

1) If you want a UDT to inherit a base UDT, how does it make sense that you don't want the bigger UDT to see all the functions of the base UDT? In what case would you want something like that? (no sense to have both protected or private)

2) Even if there was such an example, why two keywords to muddle the language? Why not just have a compound keyword, like "private inherits" (or "private extends"..) or something like that?

For fbc 0.21.1 (before inheritance):
- Protected members can only be accessed from member procedures of the Type they are declared in. They are also accessible to outside code (bad behavior).
- Private members can only be accessed from member procedures of the Type they are declared in. They are not accessible to outside code.

I checked the 2 keywords 'Protected' and 'Private' work now (for fbc With inheritance) as specified:
- Protected members can only be accessed from member procedures of the Type they are declared in, or member procedures of a derived Type. They are not accessible to outside code.
- Private members can only be accessed from member procedures of the Type they are declared in. They are not accessible to outside code or member procedures from a derived Type.
marcov
Posts: 2767
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Postby marcov » May 01, 2011 12:30

Protected is mostly for people working with complex class hierarchies, to mark internal methods that should be visible for descendants, but are not for end user use.

I have no idea why you would want compound identifiers here.

Return to “Community Discussion”

Who is online

Users browsing this forum: MSN [Bot] and 28 guests