http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46641
Summary: Specification-expr checks and results with C_SIZEOF and SIZEOF Product: gcc Version: 4.6.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: fortran AssignedTo: unassig...@gcc.gnu.org ReportedBy: bur...@gcc.gnu.org Kind of follow up to PR 46638; based on http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/1b907e3b7b6f3461 There is something fishy about the following program. In terms of validity, the question is whether C_SIZEOF (structure-constructor ()) is a valid initialization expression -- gfortran accepts it. Besides the validity issue, there is something fishy. The "string" has a length of 16 -- using either C_SIZEOF or the literal 16 in the declaration. However, if one uses the literal, it works while using C_SIZEOF the TRANSFER seems to override some memory it shouldn't - causing a segfault. Using "sizeof()" instead of "c_sizeof()", the either version is rejected by the Cray compiler - but both version work with ifort. Neither compiler likes the C_sizeof version (not implemented in Cray, not sure about ifort). gfortran prints for sizeof the error "must have constant character length" for both versions. module utils use ISO_C_BINDING implicit none type, bind(C) :: CPUID_type integer(C_INT32_T) eax integer(C_INT32_T) ebx integer(C_INT32_T) edx integer(C_INT32_T) ecx end type CPUID_type type(CPUID_type) :: test_type end module utils program mxcsr_test use ISO_C_BINDING use utils implicit none integer(C_INT32_T) reg integer(C_INT64_T) ts1, ts2 integer(C_INT16_T) sw, cw integer(C_INT32_T) eax, ecx type(CPUID_type) result ! Works: ! character(16) string ! Compiles but fails: character(SIZEOF(CPUID_type(0,0,0,0))) string ! Rejected with: must have constant character length ! character(SIZEOF(test_type)) string result = CPUID_TYPE(int(Z'0000000A'),int(Z'756E6547'), & int(Z'49656E69'),int(Z'6C65746E')) print *, len(string) ! OK: 16 string = transfer(result,string) write(*,'(a,a)') 'Brand name: ',string(5:16) write(*,'(4(z8.8:1x))') result end program mxcsr_test