Evaluation Order in Function Declaration

Discussion in 'C Programming' started by Shao Miller, Feb 28, 2012.

  1. Shao Miller

    Shao Miller Guest

    Is the evaluation order guaranteed to be left-to-right for the
    declaration of 'baz' in the following code? Or are the array size
    expressions unsequenced relative to one another, as in 'a + b'? Or
    something else?

    #include <stdio.h>

    int foo(void) { puts("foo"); return 1; }
    int bar(void) { puts("bar"); return 1; }

    int baz(int (* x)[foo()], int (* y)[bar()]) { return 0; }

    int main(void) { return baz(0, 0); }
    Shao Miller, Feb 28, 2012
    #1
    1. Advertising

  2. Shao Miller

    Jens Gustedt Guest

    Hello,

    Am 02/28/2012 06:22 AM, schrieb Shao Miller:
    > Is the evaluation order guaranteed to be left-to-right for the
    > declaration of 'baz' in the following code? Or are the array size
    > expressions unsequenced relative to one another, as in 'a + b'? Or
    > something else?
    >
    > #include <stdio.h>
    >
    > int foo(void) { puts("foo"); return 1; }
    > int bar(void) { puts("bar"); return 1; }
    >
    > int baz(int (* x)[foo()], int (* y)[bar()]) { return 0; }
    >
    > int main(void) { return baz(0, 0); }


    Yes, not only that it is left to right, you are even allowed to use each
    of the preceding identifiers in the expressions. Otherwise things like

    double sum(size_t n, size_t m, double A[n][m]) { ... }

    could never work reliably.

    Jens
    Jens Gustedt, Feb 28, 2012
    #2
    1. Advertising

  3. Shao Miller

    Kaz Kylheku Guest

    On 2012-02-28, Jens Gustedt <> wrote:
    > Hello,
    >
    > Am 02/28/2012 06:22 AM, schrieb Shao Miller:
    >> Is the evaluation order guaranteed to be left-to-right for the
    >> declaration of 'baz' in the following code? Or are the array size
    >> expressions unsequenced relative to one another, as in 'a + b'? Or
    >> something else?
    >>
    >> #include <stdio.h>
    >>
    >> int foo(void) { puts("foo"); return 1; }
    >> int bar(void) { puts("bar"); return 1; }
    >>
    >> int baz(int (* x)[foo()], int (* y)[bar()]) { return 0; }
    >>
    >> int main(void) { return baz(0, 0); }

    >
    > Yes, not only that it is left to right, you are even allowed to use each
    > of the preceding identifiers in the expressions. Otherwise things like
    >
    > double sum(size_t n, size_t m, double A[n][m]) { ... }
    >
    > could never work reliably.


    Sure they could. The above could mean that A[n][m], n and m independently
    receive values from the same sources (the argument expressions). The [n][m]
    doesn't have to refer to the values stored in the parameters n, and m
    but rather the [n][m] can indicate additional sinks for the data flows
    emanating from argument 1 and 2.

    Such semantics can be hammered out. There is no end to how you can lay weasely
    traps for the programmer (as the sordid history of this language shows.)
    Kaz Kylheku, Feb 28, 2012
    #3
  4. Shao Miller

    Jens Gustedt Guest

    Am 02/28/2012 10:31 AM, schrieb Kaz Kylheku:
    > On 2012-02-28, Jens Gustedt <> wrote:
    >> Hello,
    >>
    >> Am 02/28/2012 06:22 AM, schrieb Shao Miller:
    >>> Is the evaluation order guaranteed to be left-to-right for the
    >>> declaration of 'baz' in the following code? Or are the array size
    >>> expressions unsequenced relative to one another, as in 'a + b'? Or
    >>> something else?
    >>>
    >>> #include <stdio.h>
    >>>
    >>> int foo(void) { puts("foo"); return 1; }
    >>> int bar(void) { puts("bar"); return 1; }
    >>>
    >>> int baz(int (* x)[foo()], int (* y)[bar()]) { return 0; }
    >>>
    >>> int main(void) { return baz(0, 0); }

    >>
    >> Yes, not only that it is left to right, you are even allowed to use each
    >> of the preceding identifiers in the expressions. Otherwise things like
    >>
    >> double sum(size_t n, size_t m, double A[n][m]) { ... }
    >>
    >> could never work reliably.

    >
    > Sure they could. The above could mean that A[n][m], n and m independently
    > receive values from the same sources (the argument expressions). The [n][m]
    > doesn't have to refer to the values stored in the parameters n, and m
    > but rather the [n][m] can indicate additional sinks for the data flows
    > emanating from argument 1 and 2.


    theoretically they could. pratically the standard says that the
    identifier n for example is visible for the declaration of A

    > Such semantics can be hammered out. There is no end to how you can lay weasely
    > traps for the programmer (as the sordid history of this language shows.)


    sure, I just don't see how your comment is related to the question
    Shao had and how with any respect it would be helpful. You seem to
    find it necessary to rant against VLA in any form you see them. Not
    very helpful for anybody, probably not even for yourself.

    Jens
    Jens Gustedt, Feb 28, 2012
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bhushit Joshipura
    Replies:
    18
    Views:
    511
    David Harmon
    Jan 19, 2004
  2. Bhushit Joshipura

    Order of evaluation and better declaration of functions

    Bhushit Joshipura, Jan 4, 2004, in forum: C Programming
    Replies:
    26
    Views:
    592
    August Derleth
    Jan 21, 2004
  3. Ilias Lazaridis
    Replies:
    2
    Views:
    388
    Ilias Lazaridis
    Apr 24, 2005
  4. Ilias Lazaridis
    Replies:
    74
    Views:
    744
    Ilias Lazaridis
    Apr 4, 2005
  5. Ilias Lazaridis
    Replies:
    18
    Views:
    328
    Bill Guindon
    Apr 9, 2005
Loading...

Share This Page