[J3] [EXTERNAL] Re: Simple functions in Constant Expressions

Brad Richardson everythingfunctional at protonmail.com
Wed Aug 25 17:08:42 UTC 2021


Exactly. Just because a procedure can't be evaluated at compile time, doesn't mean it can't be evaluated before program start. I understand it can be tricky in practice, but it's not impossible.

Thanks for the example Tom

On Wed, 2021-08-25 at 16:56 +0000, Clune, Thomas L. (GSFC-6101) wrote:

> Of course, there can be useful/amusing/scary/dreadful consequences if one allows _non_ simple functions to be used for initialization expressions. C++ allows the equivalent, and I have my favorite Fortran program:
>
> program main
>
> end program
>
> (And this version is the verbose version!)
>
> Running it produces all sorts of output just by virtue of linking to a DSO with C++ static variables initialized with functions. What’s more those C++ functions actually call Fortran procedures. All carefully done with extern “C” and bind(C) of course, so technically portable.
>
> So if you ever wonder why a given program does not appear to behave as expected, remember the program above.
>
> - Tom
>
> From:J3 <j3-bounces at mailman.j3-fortran.org> on behalf of j3 <j3 at mailman.j3-fortran.org>
> Reply-To: j3 <j3 at mailman.j3-fortran.org>
> Date: Wednesday, August 25, 2021 at 12:44 PM
> To: Brad Richardson <everythingfunctional at protonmail.com>, j3 <j3 at mailman.j3-fortran.org>
> Cc: Vipul Parekh <parekhvs at gmail.com>
> Subject: [EXTERNAL] Re: [J3] Simple functions in Constant Expressions
>
> On Wed, Aug 25, 2021 at 12:23 PM Brad Richardson via J3 <j3 at mailman.j3-fortran.org> wrote:
>
>> ..
>>
>> There have been requests in a few places asking for something equivalent to C++'s `constexpr`. Looking at the recently added `simple` feature, I think the constraints are sufficient for `simple function`s to be effectively `constexpr`. Would it be possible to add `simple` functions to the section on Constant Expressions (Section 10.1.12).
>
> Around the time of the Tokyo meeting m219 that I could not join due to financial constraints with not having my employer or a sponsor to back attendance at Fortran standard meetings, I reached out to Malcolm who had posted paper (19-201) with the same request as Brad above.
>
> Malcolm's reply was a firm no, it can't be done, that the US15 worklist item approved by WG5 toward Fortran 202X can allow *executable code* in SIMPLE procedures which cannot be in constant expressions.
>
> I don't know if the thinking still holds, I will be rather curious about this.
>
> Ondrej has brought up the GitHub based "community" forum to brainstorm ideas toward Fortran 202Y proposals and Steve/WG5 appears to have at least verbally lent support toward the premise. If so, please see this thread at that forum titled, "Add CONSTEXPR procedures in Fortran":
>
> [https://github.com/j3-fortran/fortran_proposals/issues/214](https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fj3-fortran%2Ffortran_proposals%2Fissues%2F214&data=04%7C01%7Cthomas.l.clune%40nasa.gov%7Ccafd3d9fab3c4308366d08d967e787ff%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C637655066400142798%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=bCI5wkKSWL3psypc6zDOkh5jS8ANDz%2BjbMnkoNgHdlw%3D&reserved=0)
>
> It will be nice if all the members of J3 who have *voting* privilege and those who represent member countries toward WG5 can also start using the GitHub forum and start providing feedback on idea proposals, simple "thumbs down" or "thumbs up" and if that is NOT "politically" correct somehow, then to post a few words that provide technical guidance as to why something is not a good idea, or how to make it a good one, or acknowledge the idea is worthy of further consideration.
>
> Thanks,
>
> Vipul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210825/d5aa3181/attachment.htm>


More information about the J3 mailing list