question about calling func( z, z++, z++ )

Discussion in 'C Programming' started by Chad, Oct 7, 2009.

  1. Chad

    Chad Guest

    In the following code, there is a something like func( z, z++, z++ )

    [cdalten@localhost oakland]$ more luc.c
    #include <stdio.h>

    int func( int a, int b, int c )
    {
    printf( "a is %d and b is %d and c is %d\n", a, b, c );
    return(c);
    }

    int main( void )
    {
    int z = 9;
    func( z, z++, z++ );

    return 0;
    }
    [cdalten@localhost oakland]$ gcc -Wall luc.c -o luc
    luc.c: In function ‘main’:
    luc.c:12: warning: operation on ‘z’ may be undefined
    luc.c:12: warning: operation on ‘z’ may be undefined
    [cdalten@localhost oakland]$ ./luc
    a is 11 and b is 10 and c is 9
    [cdalten@localhost oakland]$

    Is func( z, z++, z++) a constraint violation?

    Chad
     
    Chad, Oct 7, 2009
    #1
    1. Advertising

  2. Chad <> writes:
    [...]
    > Is func( z, z++, z++) a constraint violation?


    No, but its behavior is undefined.

    See section 3 of the comp.lang.c FAQ, <http://www.c-faq.com/>.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Oct 7, 2009
    #2
    1. Advertising

  3. Chad

    gwowen Guest

    On Oct 7, 2:20 am, Keith Thompson <> wrote:

    > > Is func( z, z++, z++) a constraint violation?

    > No, but its behavior is undefined.
    >
    > See section 3 of the comp.lang.c FAQ, <http://www.c-faq.com/>.


    Come on Keith. Do you really think a genuine newbie, unaware that

    f(z,z++);

    is UB is going to use the term "constraint violation"?
     
    gwowen, Oct 7, 2009
    #3
  4. On 7 Oct, 08:45, gwowen <> wrote:
    > On Oct 7, 2:20 am, Keith Thompson <> wrote:


    > > > Is func( z, z++, z++) a constraint violation?

    >
    > > No, but its behavior is undefined.
    > > See section 3 of the comp.lang.c FAQ, <http://www.c-faq.com/>.

    >
    > Come on Keith.  Do you really think a genuine newbie, unaware that
    >
    > f(z,z++);
    >
    > is UB is going to use the term "constraint violation"?


    well he knew it might be wrong and now he knows its wrong and
    what sort of wrong
     
    Nick Keighley, Oct 7, 2009
    #4
  5. Chad

    gwowen Guest

    On Oct 7, 12:50 pm, James Kuyper <> wrote:

    > No, but a near-newbie, aware of the existence of constraint violations,


    Really? A near newbie who writes in standard-ese?
    No-one unconversant with the standard talks about "constraint
    violations",
    they call them "programming/syntax errors" or "bad code" or
    "disallowed code".

    So sure, Chad could be someone who has read the standard well enough
    to know
    the terminology, but not understood it well enough to recognise f(z,z+
    +).
    Oh, and has not followed this group long enough to see the 30 times
    this
    question has been asked in the last 3 months.

    That's not completely impossible, but, given the usual level of debate
    in c.l.c.,
    does it not strike you as considerably less likely than the fact its a
    wind-up?
     
    gwowen, Oct 7, 2009
    #5
  6. Chad

    chad Guest

    On Oct 7, 5:51 am, gwowen <> wrote:
    > On Oct 7, 12:50 pm, James Kuyper <> wrote:
    >
    > > No, but a near-newbie, aware of the existence of constraint violations,

    >
    > Really? A near newbie who writes in standard-ese?
    > No-one unconversant with the standard talks about "constraint
    > violations",
    > they call them "programming/syntax errors" or "bad code" or
    > "disallowed code".
    >
    > So sure, Chad could be someone who has read the standard well enough
    > to know
    > the terminology, but not understood it well enough to recognise f(z,z+
    > +).


    I have some idea what a constraint violation is. However, I didn't
    know it well enough to recognize if func( z, z++, z++ ) was or wasn't
    a constraint violation. Hence why I had asked.

    > Oh, and has not followed this group long enough to see the 30 times
    > this
    > question has been asked in the last 3 months.
    >


    I've been sporadically following this group for the past few years.
    And when I do read it, I normally just do a brief scan over the recent
    posts.

    > That's not completely impossible, but, given the usual level of debate
    > in c.l.c.,
    > does it not strike you as considerably less likely than the fact its a
    > wind-up?
     
    chad, Oct 7, 2009
    #6
  7. Chad

    Eric Sosman Guest

    gwowen wrote:
    > On Oct 7, 2:20 am, Keith Thompson <> wrote:
    >
    >>> Is func( z, z++, z++) a constraint violation?

    >> No, but its behavior is undefined.
    >>
    >> See section 3 of the comp.lang.c FAQ, <http://www.c-faq.com/>.

    >
    > Come on Keith. Do you really think a genuine newbie, unaware that
    >
    > f(z,z++);
    >
    > is UB is going to use the term "constraint violation"?


    If he's the same "Chad" who's been here on and off for
    several years now, he's not a "genuine newbie."

    --
    Eric Sosman
    lid
     
    Eric Sosman, Oct 7, 2009
    #7
  8. Chad

    jameskuyper Guest

    gwowen wrote:
    > On Oct 7, 12:50 pm, James Kuyper <> wrote:
    >
    > > No, but a near-newbie, aware of the existence of constraint violations,

    >
    > Really? A near newbie who writes in standard-ese?
    > No-one unconversant with the standard talks about "constraint
    > violations",
    > they call them "programming/syntax errors" or "bad code" or
    > "disallowed code".


    You don't have to be conversant with the standard; reading this
    newsgroup is sufficient to acquaint someone with that terminology.

    > So sure, Chad could be someone who has read the standard well enough
    > to know
    > the terminology, but not understood it well enough to recognise f(z,z+
    > +).



    Believe it or not, there's a large chunk of the learning curve between
    becoming aware of the concept of a "constraint violation", and
    becoming sufficiently familiar with the standard to reliably guess
    whether a given problem is a constraint violation, a syntax error, or
    undefined behaviour. People call me a language lawyer; I myself only
    reached the point, a year or two ago, where I could answer such
    questions with reasonable reliability without first double-checking
    what the standard says. Even now I still make occasional mistakes.

    > That's not completely impossible, but, given the usual level of debate
    > in c.l.c.,
    > does it not strike you as considerably less likely than the fact its a
    > wind-up?


    It's possible, but I have nowhere near as much certainty about that
    point as you have.
     
    jameskuyper, Oct 7, 2009
    #8
  9. chad <> writes:
    [...]
    > I have some idea what a constraint violation is. However, I didn't
    > know it well enough to recognize if func( z, z++, z++ ) was or wasn't
    > a constraint violation. Hence why I had asked.

    [...]

    Keep in mind that a constraint violation is something that must be
    diagnosed at compile time. A clever compiler *could* recognize that
    func( z, z++, z++ ) violates the rules, but it would require analysis
    of a kind that compilers are not generally required to perform.

    Consider
    func( *p0, (*p1)++, (*p2)++ )
    where p0, p1, and p2 are pointers. If they all point to different
    objects, this is fine. If any two of them point to the same object,
    the behavior is undefined, for exactly the same reason that the
    behavior of
    func( z, z++, z++ )
    is undefined. Since the values of p0, p1, and p2 cannot in general be
    known at compile time, the standard doesn't require the compiler to
    recognize that there's a problem -- hence the behavior is undefined.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Oct 7, 2009
    #9
  10. Frank <> writes:
    [...]
    >> chad <> writes:

    [...]
    >>> I have some idea what a constraint violation is. However, I didn't
    >>> know it well enough to recognize if func( z, z++, z++ ) was or wasn't
    >>> a constraint violation. Hence why I had asked.

    >> [...]

    [...]
    >
    > There's no sequence point to be between the modifications of the object.
    >
    > Keith, is it illegal to have a comma operator as any of the commas above?


    Not illegal exactly. The commas in func( z, z++, z++ ) simply aren't
    comma operators. The syntax of a function call is:

    postfix-expression
    (
    zero or more assignment-expressions, separated by commas
    )

    If you want a comma operator in a function call, you can parenthesize
    it:

    func( (a, b), (c, d), (e, f) )

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Oct 8, 2009
    #10
  11. Chad

    Frank Guest

    In Dread Ink, the Grave Hand of Keith Thompson Did Inscribe:

    > chad <> writes:
    > [...]
    >> I have some idea what a constraint violation is. However, I didn't
    >> know it well enough to recognize if func( z, z++, z++ ) was or wasn't
    >> a constraint violation. Hence why I had asked.

    > [...]
    >
    > Keep in mind that a constraint violation is something that must be
    > diagnosed at compile time. A clever compiler *could* recognize that
    > func( z, z++, z++ ) violates the rules, but it would require analysis
    > of a kind that compilers are not generally required to perform.
    >
    > Consider
    > func( *p0, (*p1)++, (*p2)++ )
    > where p0, p1, and p2 are pointers. If they all point to different
    > objects, this is fine. If any two of them point to the same object,
    > the behavior is undefined, for exactly the same reason that the
    > behavior of
    > func( z, z++, z++ )
    > is undefined. Since the values of p0, p1, and p2 cannot in general be
    > known at compile time, the standard doesn't require the compiler to
    > recognize that there's a problem -- hence the behavior is undefined.


    Chad and I seem to be persons who return to clc occasionally as
    autodidacts. I think I remember him.

    There's no sequence point to be between the modifications of the object.

    Keith, is it illegal to have a comma operator as any of the commas above?
    --
    Frank

    Listen to me. I'm should-ing all over myself.
    ~~ Al Franken
     
    Frank, Oct 8, 2009
    #11
  12. Keith Thompson <> wrote:
    > ... Keep in mind that a constraint violation is something
    > that must be diagnosed at compile time. ...


    A few nits:

    - Interpreters don't do compilation.

    - 6.10 (Preprocessing directives) has quite a few constraints.

    - I don't think the standard specifies _when_ a constraint is
    to be issued.

    I'm a bit surprised that unresolved external identifiers are
    not constraint violations, but there you go.

    --
    Peter
     
    Peter Nilsson, Oct 8, 2009
    #12
  13. Chad

    Frank Guest

    In Dread Ink, the Grave Hand of Keith Thompson Did Inscribe:

    > Frank <> writes:
    > [...]
    >>> chad <> writes:

    > [...]
    >>>> I have some idea what a constraint violation is. However, I didn't
    >>>> know it well enough to recognize if func( z, z++, z++ ) was or wasn't
    >>>> a constraint violation. Hence why I had asked.
    >>> [...]

    > [...]
    >>
    >> There's no sequence point to be between the modifications of the object.
    >>
    >> Keith, is it illegal to have a comma operator as any of the commas above?

    >
    > Not illegal exactly. The commas in func( z, z++, z++ ) simply aren't
    > comma operators. The syntax of a function call is:
    >
    > postfix-expression
    > (
    > zero or more assignment-expressions, separated by commas
    > )
    >
    > If you want a comma operator in a function call, you can parenthesize
    > it:
    >
    > func( (a, b), (c, d), (e, f) )


    I see. So func is still gonna have three arguments.
    --
    Frank

    I once asked the most fabulous couple I know, Madonna and Guy Ritchie, how
    they kept things fresh despite having been married for almost seven months.
    'It's a job, Al,' Guy told me. 'We work at it every day.'
    ~~ Al Franken,
     
    Frank, Oct 8, 2009
    #13
  14. Chad

    Phil Carmody Guest

    Keith Thompson <> writes:
    > Chad <> writes:
    > [...]
    >> Is func( z, z++, z++) a constraint violation?

    >
    > No, but its behavior is undefined.


    Yes, it indeed violates the contraints that guarantee definedness
    of the behaviour.

    Phil
    --
    Any true emperor never needs to wear clothes. -- Devany on r.a.s.f1
     
    Phil Carmody, Oct 8, 2009
    #14
  15. Chad

    James Kuyper Guest

    Phil Carmody wrote:
    > Keith Thompson <> writes:
    >> Chad <> writes:
    >> [...]
    >>> Is func( z, z++, z++) a constraint violation?

    >> No, but its behavior is undefined.

    >
    > Yes, it indeed violates the contraints that guarantee definedness
    > of the behaviour.


    Could you identify those constraints by section and paragraph?
     
    James Kuyper, Oct 8, 2009
    #15
  16. Phil Carmody <> writes:
    > Keith Thompson <> writes:
    >> Chad <> writes:
    >> [...]
    >>> Is func( z, z++, z++) a constraint violation?

    >>
    >> No, but its behavior is undefined.

    >
    > Yes, it indeed violates the contraints that guarantee definedness
    > of the behaviour.


    "Constraint" has a specific meaning in C. func(z, z++, z++)
    violates no constraint.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Oct 8, 2009
    #16
  17. Chad

    Tim Rentsch Guest

    Peter Nilsson <> writes:

    > Keith Thompson <> wrote:
    >> ... Keep in mind that a constraint violation is something
    >> that must be diagnosed at compile time. ...

    >
    > A few nits:
    >
    > - Interpreters don't do compilation.
    >
    > - 6.10 (Preprocessing directives) has quite a few constraints.
    >
    > - I don't think the standard specifies _when_ a constraint is
    > to be issued.


    Not directly, but the Standard does distinguish translation
    and execution. If a constraint violation occurs during
    translation, it seems like a diagnostic must be issued
    at that point, since if it weren't the implementation
    might not be able to fulfill its obligation to issue
    the diagnostic. There is no requirement that execution
    must be requested, but there is a requirement that
    a diagnostic be issued.
     
    Tim Rentsch, Oct 8, 2009
    #17
  18. Chad

    Phil Carmody Guest

    James Kuyper <> writes:
    > Phil Carmody wrote:
    >> Keith Thompson <> writes:
    >>> Chad <> writes:
    >>> [...]
    >>>> Is func( z, z++, z++) a constraint violation?
    >>> No, but its behavior is undefined.

    >>
    >> Yes, it indeed violates the contraints that guarantee definedness of
    >> the behaviour.

    >
    > Could you identify those constraints by section and paragraph?


    Can you identify the section which indicates that it's UB?

    Phil
    --
    Any true emperor never needs to wear clothes. -- Devany on r.a.s.f1
     
    Phil Carmody, Oct 8, 2009
    #18
  19. Chad

    Phil Carmody Guest

    Keith Thompson <> writes:
    > Phil Carmody <> writes:
    >> Keith Thompson <> writes:
    >>> Chad <> writes:
    >>> [...]
    >>>> Is func( z, z++, z++) a constraint violation?
    >>>
    >>> No, but its behavior is undefined.

    >>
    >> Yes, it indeed violates the contraints that guarantee definedness
    >> of the behaviour.

    >
    > "Constraint" has a specific meaning in C. func(z, z++, z++)
    > violates no constraint.


    It also has a specific meaning in English.

    If you left your Plaugher next to an electric heater - would it char?

    Phil
    --
    Any true emperor never needs to wear clothes. -- Devany on r.a.s.f1
     
    Phil Carmody, Oct 8, 2009
    #19
  20. Chad

    jameskuyper Guest

    Phil Carmody wrote:
    > James Kuyper <> writes:
    > > Phil Carmody wrote:
    > >> Keith Thompson <> writes:
    > >>> Chad <> writes:
    > >>> [...]
    > >>>> Is func( z, z++, z++) a constraint violation?
    > >>> No, but its behavior is undefined.
    > >>
    > >> Yes, it indeed violates the contraints that guarantee definedness of
    > >> the behaviour.

    > >
    > > Could you identify those constraints by section and paragraph?

    >
    > Can you identify the section which indicates that it's UB?


    Yes: 6.5p2.
    Your turn.
     
    jameskuyper, Oct 8, 2009
    #20
    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. CRON
    Replies:
    24
    Views:
    203,883
    Adrienne Boswell
    Jun 20, 2006
  2. Johnny
    Replies:
    3
    Views:
    485
    Robert Kern
    Aug 23, 2005
  3. Hari Sekhon
    Replies:
    0
    Views:
    559
    Hari Sekhon
    Jun 20, 2006
  4. Vinko Vrsalovic

    int func() v/s int func(void)

    Vinko Vrsalovic, Jan 21, 2005, in forum: C Programming
    Replies:
    14
    Views:
    1,373
    Villy Kruse
    Jan 24, 2005
  5. Alex Vinokur
    Replies:
    6
    Views:
    387
    Tor Rustad
    Nov 18, 2006
Loading...

Share This Page