Type and Scope Confusion - Beginner

New to FreeBASIC? Post your questions here.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Type and Scope Confusion - Beginner

Post by deltarho[1859] »

I go to Index of /stw/builds once a week to check on the FreeBASIC manual. It is updated very regularly. The latest is dated 2018.03.25.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Type and Scope Confusion - Beginner

Post by dodicat »

I suppose therein lies the new changelog?
I think phantom UDT's are just as real as real UDT's within their own scope.

Code: Select all

 
Screen 19
Type udt
    As Single x
    As Single y
    As Single dx
    As Single dy
    As String k,t
    Declare Sub show(as ulong)
    Declare Constructor(As Long=0)
    declare sub main
End Type

Constructor udt(n As Long)
Select Case n
Case 1
    x=1
    y=1
    dx=.5
    dy=.3
Case 2
    Static As Single xx=200,yy=200
    Static As Single dxx=.5,dyy=-.3
    xx+=dxx
    yy+=dyy
    If xx<0 Or xx>800 Then dxx=-dxx
    If yy<0 Or yy>600 Then dyy=-dyy
    x=xx
    y=yy
    t="2"
End Select 
End Constructor

Sub udt.show(c as ulong)
    Circle(x,y),5,c,,,,f
    draw string(x,y-20),t,c
    k=Inkey
End Sub

sub udt.main
With udt(1)
    Do
        .x+=.dx
        .y+=.dy
        If .x<0 Or .x>800 Then .dx=-.dx
        If .y<0 Or .y>600 Then .dy=-.dy
        .t="1"
        Screenlock
        Cls
        .show(15)
        With udt(2)
            .show(3)
        End With
        Screenunlock
        Sleep 1,1
    Loop Until .k=Chr(27)
End With
end sub

type<udt>.main



 
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Type and Scope Confusion - Beginner

Post by MrSwiss »

dodicat wrote:Do we have to recompile the compiler to make use of these fixes/updates?
No, you don't.
They are also found, on the link posted by DeltaRho[] (for manual).
dodicat wrote:If not, where can beginners get hold of the compiler?
Those are "unofficial" builds (call them: experimental), only.
Incomplete bindings etc., therefore, no good for beginners, they should use "official" builds only.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Type and Scope Confusion - Beginner

Post by deltarho[1859] »

I would never post code compiled with 1.06 until it is 'official'.

Here is the 1.06.0 change log although some of it could be written in Latin for what I understand of it.
Version 1.06.0

[changed]
- Adjusted warning text for "mixed bool/nonbool operands" warning
- test-suite uses libfbcunit for unit testing framework

[added]
- -noobjinfo option to disable the writing/reading of compile-time library and other linking options from/to .o and .a files. This also disables the use of fbextra.x (the supplemental linker script) for discarding the .fbctinf sections, which is useful when using the gold linker that doesn't support this kind of linker script.
- Linux console Inkey() now recognizes F11 and F12
- 2D render through OpenGL on Windows and Linux via screencontrol (angros47)
- Windows API binding updated to additionally support _WIN32_WINNT &h0501, &h0600, &h0601
- Under X11, ScreenControl GET_WINDOW_HANDLE places the Display ptr in param2
- Updated bindings: SDL2 2.0.6, SDL2_image 2.0.1, SDL2_mixer 2.0.1, SDL2_net 2.0.1, SDL2_ttf 2.0.14

[fixed]
- win/d3dx9.bi no longer has a hard-coded #inclib "d3dx9d". d3dx9d.dll is apparently not a generally valid choice. In practice programs have to be linked against d3dx9_33.dll or d3dx9_39.dll, etc.
- #816: The ASM backend contained a bad assert() which could be triggered in debug builds of the compiler, when generating code for certain array accesses
- C backend: undefined behaviour (inherited from C) in case of signed integer overflow
- C backend: undefined behaviour (inherited from C) in case of SHL/SHR operations with a shift amount >= the bitsize of the shifted operand in bits (if the shift amount wasn't a compile-time constant)
- utf_conv.bi: When given a NULL destination buffer, no-op conversions (UTF16 => UTF16 or UTF32 => UTF32) didn't allocate a new buffer, but just returned the source buffer, violating the contract used for proper conversions (which allocate a new buffer if a NULL destination is passed).
- utf_conv.bi: In UTF8 => UTF16/32 and UTF32 => UTF16 conversions, strings longer than 8 chars could be truncated
- #797: False-positive warnings when mixing booleans with comparisons in logic operations
- TRE binding: Didn't compile with TRE_USE_SYSTEM_REGEX_H
- LLVM backend: Emit the new (LLVM 3.7+) load-syntax
- When compiling .rc files with windres instead of GoRC (happens with non-standalone fbc), the current directory is now an include search directory, to match the GoRC behaviour.
- #659: Keep the stack 16-byte aligned on linux-x86 and darwin-x86 to comply with ABI; fixes crashes when external libraries use SSE
- On Windows, FB console input treated multiple repeated keypresses that were merged into one event by the system as a single keypress
- Accesses to 64bit bitfields could be miscompiled or trigger a compiler crash
- #732: Virtual destructors couldn't be called on const objects
- #790: Windows API and X11 bindings: Fixed some macros where macro parameters conflicted with other identifiers or FB keywords used in the macro body
- boolean initializer values for global or static variables were not emitted properly
- Compiler crash after reporting error about REDIM on a fixed-size array field
- #827: Using the GNU gold linker (instead of ld.bfd) resulted in broken binaries due to fbextra.x, which fbc uses with ld.bfd to discard the objinfo .fbctinf sections, but is not supported by gold. Now when gold is detected, fbextra.x won't be used anymore, in order to get working binaries.
- exec() on Linux & co was broken with regards to spaces in the executable path. Spaces were converted to "\ " and then to "/ ", resulting in a different path than given.
- ASM backend: Fixed a compiler crash or potentially bad code generation in complex floating point expressions (which had enough operands to use up the x86 FPU stack, and trigger spilling of st() registers to stack)
- C backend: Pointer arithmetic on the address of variables with any pointer type gave wrong results due to bad code generation in -gen gcc for this case.
- LLVM backend: Self-BOP emitting, byref var/param accesses
- #837: Compiler hang (or assertion triggered, if enabled) for Select Case As Const with Case -1
- ASM backend: Invalid code generated for Select Case As Const jump table index when 64bit fbc cross-compiles to 32bit
- #836: The MyUdt() syntax for creating temporary objects allowed creating objects of Abstract types (with unimplemented Abstract methods)
- WString conversions from UTF32 to UTF16 produced incorrect high surrogate values (affected conversion from UTF32 to Windows WString, and from Linux WString to UTF16)
- Conversion from UTF32 to Windows WString behaved differently from other UTF32 to UTF16 conversions in FB with regards to truncating surrogate pairs when the destination buffer is full
- #839: Wstring constants could be allocated with the wrong size when cross-compiling, leading to compiler errors and/or incorrect code generation
- WCHR would produce garbage if evaluated with constant values above &h3ffff (any value up to &hffffffffU is allowed)
- WCHR would give the wrong result if given large number of arguments which were large constants
- #846: Fix compiler crash on global variable initializer with type<T>(...) expression where T isn't a UDT
- #847: Windows API binding: Fixed winnt.bi SECURITY_*_AUTHORITY initializers
- #851: '#LINE line filename' only changed the source filename in error messages, not in debug info
- #832: Fix bug allowing QB style suffixes on all keywords, regardless of -lang
- #841: The unary negation operator gave different result signedness when used on constant instead of non-constant expression. Now the result is always signed.
- Incorrect C++ mangling for BYREF parameters using built-in types
fxm
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Type and Scope Confusion - Beginner

Post by fxm »

If we come back to the original subject:
- In general, I never use shortcuts although I know them perfectly (including also empty parentheses when calling sub/function without parameters passing).
- Likewise, I never miss the "This." in field accesses from the member procedures.
- I advise you to do too, and especially if there is possibility of ambiguity.
Red2
Posts: 18
Joined: Mar 29, 2018 22:21

Re: Type and Scope Confusion - Beginner

Post by Red2 »

paul doe wrote:
D.J.Peters wrote:...
"WITH RequiredFiles" should not compile at all
RequiredFiles are a TYPE/STRUCT descriptor
but not a reference to any memory.
And indeed it doesn't, at least in the latest versions (1.05 and 1.06).

@Red2: what compiler version are you using? Perhaps yours is an old one...
The compiler that I am using is: FreeBASIC-1.05.0-win32.exe.
I really appreciate all of the prompt feedback. Thanks to ALL.
Post Reply