From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D3C4E3858D1E; Wed, 29 Mar 2023 17:50:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D3C4E3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680112205; bh=C8rGtg7WmdJ9yrYMsBBzvbMT+CluWVcl4EwxBDw8Dig=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DXqfxheecdJdXPYvkKG5YCVG3PqDG4FMz18W00JJ/1lybw/Vvexak1+GSsXCMZ3sn e11rF3QgzIyg4FI5NXZKWB1TZqqVj+1BE8wezSNz2ZEMj36CdHtE+0+6PFCO+VAAwr 6V8fqTj3rNdJOGSY0MtrVja/b3ynUOqLOb+50ISY= From: "emr-gnu at hev dot psu.edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/109322] -fc-prototypes does not correctly translate INTEGER(KIND=C_SIZE_T), and other sizes Date: Wed, 29 Mar 2023 17:50:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: emr-gnu at hev dot psu.edu X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P5 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109322 --- Comment #2 from Eric Reischer --- I can't point to a specific standard that says, "thou shalt generate output with these types..."; it's more of a "we probably should be doing this"-type thing. If you are compiling Fortran and C on the same system with the same compiler suite, this is a non-issue. However, if you are, say, creating an= API that has autogenerated files redistributed (e.g., a base Fortran package and then autogenerated and distributed C/C++ header files), the types generated using -fc-prototypes are not safely transportable to another compiler with = the requested variable sizes. This is probably better demonstrated with another example: Extending my original demonstrator, if you add a "INTEGER(KIND=3DC_INT64_T)= :: E", you get the following output: > gfortran -m32 -fc-prototypes -fsyntax-only foo.f90 long a; {...} long_long e; } bar; ------- In the above, "long_long" is nonstandard and not recognized by most compile= rs (it was apparently implemented in some locations as a workaround to a probl= em on Windows with gcc compatibility). What's worse, is if you run the above in 64-bit mode on x86 Linux, you get: > gfortran -m64 -fc-prototypes -fsyntax-only foo.f90 long a; {...} long e; } bar; ------- This is most definitely wrong -- "long" will be 64 bits on Linux, but only = 32 bits on Windows, so the size type emitted is ambiguous. Additionally, the structures will no longer be interoperable, because (again, on Windows) in C/C++ you'll get a variable "E" that will only store 32 bits, whereas in Fortran the corresponding variable will be 64 bits, thus offsetting every variable that comes after it. Probably better to be safe (and definitely mo= re portable) to leave translation of the types to when the C/C++ files are actually compiled (which may not be with gcc) by using the stdint.h types. I will stipulate that, yes, int64_t is not *guaranteed* to be exactly 64 bi= ts, and size_t is not *guaranteed* to be 32 or 64 bits (based on what architect= ure you're running). But preserving the explicitly-specified data types across= the language translation is the point here. An entirely separate argument coul= d be had for INTEGER*4, INTEGER*8, etc., but in this case, since you're explicit= ly requesting C_INTxx_T, you're getting something else entirely out of the prototype-generation subsystem.=