Menu

#858 Using "Field=1" in a composed type induces structure error when compiling with gcc 32-bit & 64-bit

closed
nobody
None
compiler
2018-10-26
2017-06-17
No

When using "Field=1" in a composed type, that induces an error in the main structure packing when compiling with gcc 32-bit and 64-bit (the same code works when compiling with gas).

Example of bug with gcc 32-bit and gcc 64-bit:

type t12byte field=1
  as longint a
  as long b
end type

type t16byte
    as t12byte a
end type

print sizeof(t12byte)
print sizeof(t16byte)

dim dummy as t16byte

Compilation error:

Compiler output:
.....\FBIDETEMP.c:15:47: error: size of array '__$fb_structsizecheck' is negative
#define __FB_STATIC_ASSERT( expr ) extern int __$fb_structsizecheck

.....\FBIDETEMP.c:20:1: note: in expansion of macro '__FB_STATIC_ASSERT'
__FB_STATIC_ASSERT( sizeof( struct $7T16BYTE ) == 16 );

Results:
Compilation failed

Discussion

  • fxm (freebasic.net)

    A workaround to the above gcc bug (32-bit and 64-bit):

    type t12byte field=1
      as longint a
      as long b
    end type
    
    type t16byte
      union
        as t12byte a
        as longint dummy
      end union
    end type
    
    print sizeof(t12byte)
    print sizeof(t16byte)
    
    dim dummy as t16byte
    
    sleep
    
     

    Last edit: fxm (freebasic.net) 2017-06-18
  • dkl

    dkl - 2018-10-26
    • status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB