Skip to content

Conversation

@jayrm
Copy link
Member

@jayrm jayrm commented Dec 30, 2020

To address #203 where it's not possible to convert / cast static initializers even though should be considered safe to do so.

sub s() 
end sub

static shared as any ptr s1 = @s
static shared as any ptr s2 = procptr( s )
static shared as any ptr s3 = cptr( any ptr, @s )
static shared as any ptr s4 = cptr( sub() ptr, @s )

'' u|integer is ok on 32-bit & 64-bit
static shared as uinteger s5 = cptr( uinteger, @s )

#ifdef __FB_64BIT__
'' u|longint only allowed on 64-bit targets
static shared as uinteger s6 = cptr( ulongint, @s )
#else
'' u|long only allowed on 32-bit targets
static shared as ulong s6 = cptr( ulong, @s )
#endif

Explicit casting of static initializers should be allowed if the sizes match.

Under the hood in fbc the conversion of an address cannot be constant folded since the symbol name needs to be emitted to the assembler, therefore evaluation of the conversion / cast is delayed until the initializer is flushed to the initializing assignment.


Take care casting away a procedures type though,
see sf.net # 889 Complex/compact syntax unsupported by gcc

@jayrm jayrm merged commit 5efd77a into freebasic:master Dec 30, 2020
@jayrm jayrm mentioned this pull request Dec 30, 2020
@jayrm jayrm deleted the git203 branch December 31, 2020 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant