D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6620 - argument evaluation order inversed for extern(C)
Summary: argument evaluation order inversed for extern(C)
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull, wrong-code
Depends on:
Blocks:
 
Reported: 2011-09-07 16:05 UTC by Martin Nowak
Modified: 2018-11-24 11:14 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Nowak 2011-09-07 16:05:10 UTC
version (none)
{
    extern(C) int bar(int a, int b) { return b - a; }
}
else
{
    int bar(int a, int b) { return b - a; }
}

void main()
{
    int i;
    assert(bar(++i, ++i) == 1);
}

---

I know argument evaluation order isn't really guaranteed to be left to right.
But having a reverse order for extern(C) calls is simply surprising.
Comment 1 yebblies 2011-09-07 21:30:51 UTC
(In reply to comment #0)
> I know argument evaluation order isn't really guaranteed to be left to right.

It isn't guaranteed _at all_, it's undefined.  I think there's already an enhancement open about defining the order of evaluation, but until that's accepted this is perfectly valid behavior by the compiler.
Comment 2 Johannes Pfau 2014-02-13 00:22:04 UTC
The pull request was accepted, LTR evaluation is now required:
https://github.com/D-Programming-Language/dlang.org/pull/6
Comment 4 Kenji Hara 2014-10-01 13:04:30 UTC
(In reply to Kenji Hara from comment #3)
> https://github.com/D-Programming-Language/dmd/pull/4035

A small supplemental documentation fix:
https://github.com/D-Programming-Language/dlang.org/pull/669
Comment 5 Nicholas Wilson 2018-11-24 11:14:12 UTC
 2.074.1: Failure with output:
-----
core.exception.AssertError@onlineapp.d(13): Assertion failure
----------------
??:? _d_assertp [0x42750d]
onlineapp.d:13 _Dmain [0x427447]
??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFNlZv [0x427857]
??:? scope void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x427787]
??:? scope void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() [0x427800]
??:? scope void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x427787]
??:? _d_run_main [0x4276f7]
??:? main [0x42746d]
??:? __libc_start_main [0x4218982f]
-----

Since      2.075.1: Success and no output